We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

how to update both column name and column value at the same time using R tool

nkazi01
7 - Meteor

Hi, my R code and output in Rstudio looks like below. How do I do the same in alteryx? 

 

data.tb 

 

## Output --> 

namedate
john smith2022-07-21

 

file.df <- data.frame(

              col_a = data.tb[1,1]

              col_b = data.tb[1,2]

              message = "hello world"

              )

file.df

 

## Output -->

namedatemessage
john smith2022-07-21hello world

 

 

Issue: when I try to do the same in alteryx, only the value is getting filled, but not the column names. I am getting below output in alteryx

 

## Output -->

col_acol_bmessage
john smith2022-07-21hello world

 

 

7 REPLIES 7
NeilR
Alteryx Alumni (Retired)

There are several ways to do this. Here's one:

 

df <- read.Alteryx("#1", mode="data.frame")
df["message"] = "hello world"
write.Alteryx(df, 1)

 

See attached...

nkazi01
7 - Meteor

Hi, thank you for your solution. But I am trying to rename the first two columns as well. 

so from col_a and col_b to name and date. I know i can use select tool to do it afterwards. But I am asking if it's possible to do it using R tool?

NeilR
Alteryx Alumni (Retired)

Some googling led me to the colnames function:

 

colnames(df)[1] <- "name"
colnames(df)[2] <- "date"

 

nkazi01
7 - Meteor

hi thank you again for your reply. Sorry I should have clarified it better. I want to update column name AND values at the same time using data from ANOTHER file. 

 

so lets say file#1 looks like below

 

col_amessage
1hello
2world

 

file#2 contains the following data

 

namedate
john2022
smith2021

 

Now i want to use the data from file#2 and replace it with column#1 in file#1 completely. 

 

so file#1 will now look like below

namemessage
johnhello
smithworld
NeilR
Alteryx Alumni (Retired)

This is pretty simple in Alteryx with the Join tool but for R I'd suggest looking into merge.

nkazi01
7 - Meteor

ok thank you i will look into it

grazitti_sapna
17 - Castor

Hello @nkazi01, try this if it helps?

grazitti_sapna_0-1658898708602.png

 

Thanks!

Sapna Gupta
Labels
Top Solution Authors