BOISSON, Pascal
2007-Mar-08 17:34 UTC
[R] sending a vector of characters as arguments for a function
Dear all, It seems to be a recurrent problem to me and I am asking your help to get over it once for all ... My idea is : I have variables C_1, C_2, C_3 ... that corresponds to vectors of size n, and I would like to cbind them. I get a vector of their names using : temp<- ls(pat="C") And I like to find a way to use this vector temp as an argument to cbind. Unfortunately, my various trials failed, here are some samples of what I tried : Attempt : s0<-ls(pat="C") s3<-split(s0, f=s0) #as do.call need a list of arguments do.call("cbind", s3) #failed attempt : s1<-as.character(rbind(ls(pat="C"), ", ")) s2<-paste( s1[1:(length(s1)-1)], collapse="") parse(text=paste(as.character(parse(text=s2)) #I couldn't manage to get anywhere with this ... It appears that I have a problem with "expressions" management, and I couldn't find any clue in ?parse or ?expression Thanks for any comment on this Sincerely, Pascal Boisson ___________________________________________________________________________________ Protegeons ensemble l'environnement : avez-vous besoin d'imprimer ce courrier electronique ? ___________________________________________________________________________________ Les informations figurant sur cet e-mail ont un caractere strictement confidentiel et sont exclusivement adressees au destinataire mentionne ci-dessus.Tout usage, reproduction ou divulgation de cet e-mail est strictement interdit si vous n'en etes pas le destinataire. Dans ce cas, veuillez nous en avertir immediatement par la meme voie et detruire l'original. Merci This e-mail is intended only for use of the individual or entity to which it is addressed and may contain information that is privileged, confidential and exempt from disclosure under applicable law. Any use, distribution or copying of this e-mail communication is strictly prohibited if you are not the addressee. If so, please notify us immediately by e-mail, and destroy the original. Thank you. [[alternative HTML version deleted]]
rolf at math.unb.ca
2007-Mar-08 17:48 UTC
[R] sending a vector of characters as arguments for a function
Pascal Boisson wrote: <snip>> I have variables C_1, C_2, C_3 ... that corresponds to vectors of size > n, and I would like to cbind them. > > I get a vector of their names using : temp<- ls(pat="C") > > And I like to find a way to use this vector temp as an argument to > cbind. > > Unfortunately, my various trials failed, here are some samples of what I > tried :<snip> Try: s0 <- ls(pat="^C") # Notice the ``^'' --- for safety. m <- do.call("cbind",lapply(s0,"get")) # Names get lost. colnames(m) <- s0 # So tack them on. cheers, Rolf Turner rolf at math.unb.ca
Gabor Grothendieck
2007-Mar-08 19:10 UTC
[R] sending a vector of characters as arguments for a function
Try this: C1 <- 1:3 C2 <- 4:6 sapply(ls(pattern = "C"), get) On 3/8/07, BOISSON, Pascal <Pascal.BOISSON at veolia.com> wrote:> Dear all, > > > > It seems to be a recurrent problem to me and I am asking your help to > get over it once for all ... > > > > My idea is : > > > > I have variables C_1, C_2, C_3 ... that corresponds to vectors of size > n, and I would like to cbind them. > > > > I get a vector of their names using : temp<- ls(pat="C") > > And I like to find a way to use this vector temp as an argument to > cbind. > > > > Unfortunately, my various trials failed, here are some samples of what I > tried : > > > > > > Attempt : > > s0<-ls(pat="C") > > s3<-split(s0, f=s0) #as do.call need a list of arguments > > do.call("cbind", s3) #failed > > > > > > attempt : > > s1<-as.character(rbind(ls(pat="C"), ", ")) > > s2<-paste( s1[1:(length(s1)-1)], collapse="") > > > > parse(text=paste(as.character(parse(text=s2)) #I couldn't manage to > get anywhere with this ... > > > > It appears that I have a problem with "expressions" management, and I > couldn't find any clue in ?parse or ?expression > > > > Thanks for any comment on this > > Sincerely, > > Pascal Boisson > > > > > > ___________________________________________________________________________________ > > Protegeons ensemble l'environnement : avez-vous besoin d'imprimer ce courrier electronique ? > ___________________________________________________________________________________ > > Les informations figurant sur cet e-mail ont un caractere strictement confidentiel et sont exclusivement adressees au destinataire mentionne ci-dessus.Tout usage, reproduction ou divulgation de cet e-mail est strictement interdit si vous n'en etes pas le destinataire. Dans ce cas, veuillez nous en avertir immediatement par la meme voie et detruire l'original. Merci > > This e-mail is intended only for use of the individual or entity to which it is addressed and may contain information that is privileged, confidential and exempt from disclosure under applicable law. > Any use, distribution or copying of this e-mail communication is strictly prohibited if you are not the addressee. If so, please notify us immediately by e-mail, and destroy the original. Thank you. > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >