[R] binding vectors or matrix using their names
Patrick Burns
pburns at pburns.seanet.com
Thu Mar 25 09:18:17 CET 2004
Not at all -- I can obfuscate much better.
Bill.Venables at csiro.au wrote:
>Goodness Patrick, this must surely qualify for the obfuscated R competition finals. I love it!
>
>
>
[snip]
>
>A more serious, philosophical word on Patrick's solution. It is rarely necessary (in my limited experience, sure) to have to use parse() like this. Where it provides a quick (kludgy?) solution I often find it a useful exercise to consider alternatives. They often come out simpler and you nearly always pick up something useful in the process.
>
>Bill V.
>
>
>
>
[snip]
>
>I think you are looking for the eval-parse-text idiom:
>
>eval(parse(text=paste("cbind(", paste(my.names, collapse=", "), ")")))
>
>Patrick Burns
>
>
>
[snip]
>>>
>>>
>>>>Hello list,
>>>>I have two vectors x and x2:
>>>>
>>>>x=runif(10)
>>>>x2=runif(10)
>>>>
>>>>and one vectors with their names :
>>>>
>>>>my.names=c("x","x2")
>>>>
>>>>I would like to cbind these two vectors using their names contained
>>>>
>>>>
>>>in the
>>>
>>>
>>>>vector my.names.
>>>>
>>>>
[snip]
More information about the R-help
mailing list