Re: [R] cbind objects using character vectors
Thanks Erik and Henrique, That's what I was after. Jonas On Tue, Sep 1, 2009 at 8:08 PM, Henrique Dallazuanna www...@gmail.comwrote: Try this: sapply(vec.names, get) But for this example, you don't need for, try: dat - 1 On Tue, Sep 1, 2009 at 2:52 PM, jonas garcia garcia.jona...@googlemail.com wrote: Dear list, I have a character vector such vec.names- c(a, b) It happens that I have also two R objects called a and b that I would like to merge. Is it possible to do something like cbind(vec.names[1], vec.names[2]) ending up with the same result as cbind(a,b) Bellow is a reproducible example of what I need to to: dat- data.frame(A=seq(1,5), B=seq(6,10)) vec.names- c(a, b) for(i in 1:ncol(dat)) { tab- dat[,i]-1 assign(vec.names[i], tab) } cbind(vec.names[1], vec.names[2]) [,1] [,2] [1,] a b But I was looking after the following result (using vec.names): cbind(a,b) a b [1,] 0 5 [2,] 1 6 [3,] 2 7 [4,] 3 8 [5,] 4 9 Thanks in advance Jonas [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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.
Re: [R] cbind objects using character vectors
Not tested: Instead of: cbind(vec.names[1], vec.names[2]) cbind(get(vec.names[1]), get(vec.names[2])) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of jonas garcia Sent: Tuesday, September 01, 2009 12:53 PM To: r-help@r-project.org Subject: [R] cbind objects using character vectors Dear list, I have a character vector such vec.names- c(a, b) It happens that I have also two R objects called a and b that I would like to merge. Is it possible to do something like cbind(vec.names[1], vec.names[2]) ending up with the same result as cbind(a,b) Bellow is a reproducible example of what I need to to: dat- data.frame(A=seq(1,5), B=seq(6,10)) vec.names- c(a, b) for(i in 1:ncol(dat)) { tab- dat[,i]-1 assign(vec.names[i], tab) } cbind(vec.names[1], vec.names[2]) [,1] [,2] [1,] a b But I was looking after the following result (using vec.names): cbind(a,b) a b [1,] 0 5 [2,] 1 6 [3,] 2 7 [4,] 3 8 [5,] 4 9 Thanks in advance Jonas [[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.
Re: [R] cbind objects using character vectors
Try this: sapply(vec.names, get) But for this example, you don't need for, try: dat - 1 On Tue, Sep 1, 2009 at 2:52 PM, jonas garcia garcia.jona...@googlemail.comwrote: Dear list, I have a character vector such vec.names- c(a, b) It happens that I have also two R objects called a and b that I would like to merge. Is it possible to do something like cbind(vec.names[1], vec.names[2]) ending up with the same result as cbind(a,b) Bellow is a reproducible example of what I need to to: dat- data.frame(A=seq(1,5), B=seq(6,10)) vec.names- c(a, b) for(i in 1:ncol(dat)) { tab- dat[,i]-1 assign(vec.names[i], tab) } cbind(vec.names[1], vec.names[2]) [,1] [,2] [1,] a b But I was looking after the following result (using vec.names): cbind(a,b) a b [1,] 0 5 [2,] 1 6 [3,] 2 7 [4,] 3 8 [5,] 4 9 Thanks in advance Jonas [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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.