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
item | name | value_1 | date | value_2 |
1 | john | 1234 | 2022-08-03 | 5678 |
Output file --> output.csv
name | total_value |
john | 6912 |
Solved! Go to Solution.
Hey @nkazi01,
Here is one way to do this:
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
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
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.
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.