I am coming from STATA and would like to something as followed:
dataframe = data.frame(
a = c("test1", "test2", "test3"),
b = c(1,2,3)
)
varnames = colnames(dataframe)
head(dataframe$b) # second last line
head(dataframe$varnames[2]) # last line
My goal is that the two last lines give me the same output. Basically I would like to somehow use the value stored in varnames[2] (namely "b") and use it as an input for the last code line (as it is used in the second last line). This is quite easy with STATA but I don't know how to do it in R. Could someone help?
Thx