Re: [R] string substitution for argument in function

2012-03-26 Thread R. Michael Weylandt
'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

Re: [R] string substitution for argument in function

2012-03-26 Thread Prof. Dr. Pedro Martinez Arbizu
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

Re: [R] string substitution for argument in function

2012-03-26 Thread Prof. Dr. Pedro Martinez Arbizu
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

Re: [R] string substitution for argument in function

2012-03-25 Thread Henrique Dallazuanna
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 =

Re: [R] string substitution for argument in function

2012-03-25 Thread Weidong Gu
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

[R] string substitution for argument in function

2012-03-25 Thread Pedro Martinez
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