Specifying column names from a list in the data.frame command.
Posted
by MW Frost
on Stack Overflow
See other posts from Stack Overflow
or by MW Frost
Published on 2010-04-28T16:20:39Z
Indexed on
2010/04/28
16:23 UTC
Read the original article
Hit count: 279
r
|data.frame
I have a list called cols
with column names in it:
cols <- c('Column1','Column2','Column3')
I'd like to reproduce this command, but with a call to the list:
data.frame(Column1=rnorm(10))
Here's what happens when I try it:
> data.frame(cols[1]=rnorm(10))
Error: unexpected '=' in "data.frame(I(cols[1])="
The same thing happens if I wrap cols[1]
in I()
or eval()
.
How can I feed that item from the vector into the data.frame()
command?
© Stack Overflow or respective owner