'elem' is an attribute (the name) of the 'data' variable (bad name for
a variable), not something that is independently accessible. By very
(exceptionally!) loose analogy, think of it as being something like a
field/property of an object -- you can't get to it directly (and
that's a good thing) but
HI, thanks Weidong, Henrique,
this works for the example (may be a bad example, but it should be as
simple as possible),
This is however only a workaround to name the columns of a dataframe,
but is not addressing the problem itself, that is, how can I substitute
a string (used as argument in
Me again,
what I really dont understand is the behaivour of R here.
notice, elem is not written in "brackets", why it is interpreted as
string and not as a variable?
I would expect an error "elem not found" because it is not defined as
variable, but in contrary it is accepted as column name, see
try this:
`names<-`(rep(2, 3), a)
On Sun, Mar 25, 2012 at 6:22 PM, Pedro Martinez
wrote:
>
> hello,
> I want to iterate through a list of names and use each element as an
> argument in a function. For instance:
>
> > a = c('one','two','three')
> > data= c()
> > for(elem in a){data=cbind(elem =
Hi,
This may help
a = c('one','two','three')
data.frame(eval(substitute(rbind(var,2),list(var=a
?substitute
?eval
Weidong Gu
On Sun, Mar 25, 2012 at 5:22 PM, Pedro Martinez
wrote:
> hello,
> I want to iterate through a list of names and use each element as an
> argument in a function. F
hello,
I want to iterate through a list of names and use each element as an
argument in a function. For instance:
> a = c('one','two','three')
> data= c()
> for(elem in a){data=cbind(elem = 2,data)}
> data
elem elem elem
[1,]222
instead I want 'elem' to be substituted by the stri
6 matches
Mail list logo