I have string variable, str
, with the value "car"
. I would like to create a new column in my data frame using str
, but creates a column with the name "car"
. Below is a short example.
a<-c("Bill", "Jo", "Sue")
b<-c(3,4,10)
d<-c("Red", "Blue", "Yellow")
df<-data.frame(b,d,row.names=a)
colnames(df)<-c("age","favorite_color")
df
age favorite_color
Bill 3 Red
Jo 4 Blue
Sue 10 Yellow
str<-"car"
df$str<-character(nrow(df))
df
age favorite_color str
Bill 3 Red
Jo 4 Blue
Sue 10 Yellow
Is there a way to evaluate str
while creating the new data frame column such that the column name is "car"
.