Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
Community v19.9

The latest release includes several enhancements designed to improve your Community experience!

Learn More

Dynamically rowsum values with RTool


I have two data frames with exactly similar column names and an ID code. One dataframe is for constants and the other with actual values. Each column has 300 rows of numeric values. I would like to find a way how to add the columns that look the same. I would also like to find a way how to populate the data frame so that i do the summation five times and each iteration is based on the previous output so I used an RTool instead of using multiple transpose and summation tools. In excel, it would be easy dragging the formula.


Sorry, i'm quite new with Alteryx and I haven't thought of any way how to use macro for iteration. Anyone know how to rowsum values in similar columns from two data frames multiple times? I hope someone could help me out here


Below is the code I used in the RTool:


AlteryxFullUpdate <<- FALSE

dta.obj <- read.Alteryx("#1", mode="data.frame")
constants.obj <- read.Alteryx("#2", mode="data.frame")

overlap = intersect(names(dta.obj), names(constants.obj))
dta.obj = dta.obj[overlap] + constants.obj[overlap]

It works in Rstudio but not in Alteryx with an RTool. I get an error "Error: R (335): Error in[overlap], Year1.obj[overlap])". Attached is a sample workflow


@kris-2 I took a look at your workflow. While I admittedly have very little experience with R coding, I can maybe help you with the iteration end. 


What you can do is create whats called an iterative macro. The way you turn a workflow into a macro is by clicking in the blank space of the canvas, and going to the configuration tab on left-->Workflow-->Macro-->Dropdown to Iterative.


This type of macro allows you to simulate a "while loop" in which you can specify the number of iterations, in this case, 5 as a parameter. Here is a help page to further help you configure an iterative macro. 




Sorry I could not have been more help on the R side of things but I hope I got you in the right direction regarding the looping of an R function! Essentially you will package the R code as a tool in the macro and it can iterate through until a condition is met. 


Attached is a sample iterative macro I posted to a community question before so you have an example.