Using paste in R -



Using paste in R -

i have question regarding utilize of paste in r

a<-c(1,2,3,5,5,6,7,8) b<-c(2,3,5,6,2,3,6,7) d<-c(2,8,4,6,3,7,3,5) df<-data.frame(a,b) cbind(df,sugar=d)

using above code, got this:

> b sugar 1 1 2 2 2 2 3 8 3 3 5 4 4 5 6 6 5 5 2 3 6 6 3 7 7 7 6 3 8 8 7 5

however, wonder why couldn't same results using paste function:

name<-c("sugar","salt","fat") cbind(df,paste(name[1])=d)

any help much appreciated!!

if need create new column name stored in object, try

df[name[1]] <- d df # b sugar #1 1 2 2 #2 2 3 8 #3 3 5 4 #4 5 6 6 #5 5 2 3 #6 6 3 7 #7 7 6 3 #8 8 7 5

another alternative might utilize assign

assign('df', `[[<-`(df, name[1], value=d))

r paste

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -