I have a list called colswith column names in it:
cols <- c('Column1','Column2','Column3')
I would like to reproduce this command, but with a call to the list:
data.frame(Column1=rnorm(10))
Here is what happens when I try:
> data.frame(cols[1]=rnorm(10))
Error: unexpected '=' in "data.frame(I(cols[1])="
The same thing happens if I complete cols[1]at I()or eval().
How can I pass this element from a vector to a command data.frame()?
Update:
For some background, I defined a function calc.means()that takes a data frame and a list of variables and performs the large and complex ddply operation, adding up at the level indicated by these variables.
, data.frame(), - , calc.means() rbind() . "", rbind .
cast - ddply, , . :
cols <- c('Col1','Col2','Col3')
rbind ( calc.means(dat,cols),
data.frame(cols[1]='All', calc.means(dat, cols[2:3])),
data.frame(cols[1]='All', cols[2]='All', calc.means(dat, cols[3]))
)