Hi

r-help-boun...@r-project.org napsal dne 22.09.2009 14:57:59:

> Hi all, I have been trying to solve this problem and have had no luck so 
far.
> 
> I have numeric vectors VAR1, VAR2, and VAR3 which I am trying to cbind. 
I also
> have a character vector "VAR1,VAR2,VAR3". How do I manipulate this 
character 
> vector such that I can input a transformed version of the character 
vector 
> into cbind and have it recognize that I'm trying to refer to my numeric 
> vectors VAR1, VAR2, and VAR3.
> 
> i.e. make cbind(some transformed version of character vector) equivalent 
to 
> cbind(VAR1,VAR2,VAR3)
> 
> Alternatively, starting with the console input: VAR1 VAR2 VAR3
> how does one transform into the input VAR1,VAR2,VAR3
> 
> (to get my aformentioned character vector I am using gsub(" ",",","VAR1 
VAR2 VAR3"))

Something like this?

> mp
     [,1] [,2] [,3] [,4] [,5]
[1,]  1.5  6.5 11.5 16.5 21.5
[2,]  2.5  7.5 12.5 17.5 22.5
[3,]  3.5  8.5 13.5 18.5 23.5
[4,]  4.5  9.5 14.5 19.5 24.5

> DF<-as.data.frame(mp)
> DF[,unlist(strsplit("V1,V2,V3", ","))]
   V1  V2   V3
1 1.5 6.5 11.5
2 2.5 7.5 12.5
3 3.5 8.5 13.5
4 4.5 9.5 14.5

Regards
Petr


> 
> Thanks for the help!
> 
> Mike
> 
> 
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to