R use value of a variable as a data frame column name -


i guessing simple experienced used...how can use value of variable assign data frame column name? have simple data frame df below, , variable n changes value based on user input. how insert new data frame column has it's name value of n? ideally concatenate value of n simple string. thank you.

df<-data.frame(a=c(1,1,1),b=c(2,2,2))    b 1 1 2 2 1 2 3 1 2 

when try assign new column

n<-15 df$n<-c(3,3,3) 

the name of column n.

  b n 1 1 2 3 2 1 2 3 3 1 2 3 

it's not best idea name column number, work:

df[,paste(n)] <- c(3,3,3) 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -