Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

How to add values from different columns of input file and output it USING R ONLY

nkazi01
7 - Meteor

Hi I am inputting data from an excel file using input tool and connecting it to R. Then I want to take the value from calumn#3 and the value from column#5 and set it equal to "total_value" and and output a new excel file. I am getting error when i run the below code. Do I need to install any packages?

 

input_file <- read.Alteryx("#1",mode="data.frame")

value_1 = input_file [1,3]
value_2 = input_file [1,5]

total_value = value_1 + value_2

 

 

 

Input file --> input.csv

itemnamevalue_1datevalue_2
1john12342022-08-035678

 

 

 

Output file --> output.csv

nametotal_value
john6912

 

 

4 REPLIES 4
IraWatt
17 - Castor
17 - Castor

Hey @nkazi01,

Here is one way to do this:

IraWatt_0-1659629731048.png

input_file = read.Alteryx("#1", mode="data.frame")

value_1 = input_file[1,3]
value_2 = input_file[1,5]

name <- input_file[1,2]
total_value <- value_1 + value_2

df = data.frame(name, total_value)

write.Alteryx(df, 1)

Any questions or issues please ask

Ira Watt
Technical Consultant
Watt@Bulien.com 

nkazi01
7 - Meteor

hi @IraWatt , Thank you for your solution. But that's interesting because I tried the same and kept getting an error saying '+' operator cannot be used. But yea I was expecting it to work like that as well. Did you have to install any special package for it? Are you able to share what packages you currently have installed 

IraWatt
17 - Castor
17 - Castor

Aahhh @nkazi01  I think because your data is CSV the numbers would come in as text/string data AKA not numeric data. This would explain the error. Try adding a select tool before your code and change the data types to integers. I have no installed packages. 

nkazi01
7 - Meteor

Hi @IraWatt , yes you are right, my input files are in fact csv files. That definitely explains the error. I will try converting it using the select tool. 

Thank you very much for your help and the suggestion. 

Labels