Re: [R] Looping and paste

2011-11-24 Thread Dennis Murphy
Hi: There are two good reasons why the loop solution is not efficient in this (and related) problem(s): (i) There is more code and less transparency; (ii) the vectorized solution is four times faster. Here are the two proposed functions: # Vectorized version m1 <- function(v) paste(v, ' to ', v

Re: [R] Looping and paste

2011-11-23 Thread markm0705
And thanks fo rthe pointer to the R introduction book as well On Thu, Nov 24, 2011 at 11:00 AM, Mark Murphy wrote: > Thank you > > > On Thu, Nov 24, 2011 at 7:31 AM, B77S [via R] < > ml-node+s789695n4102066...@n4.nabble.com> wrote: > >> out <- vector("list") >> Ylab <- for(i in 1:length(BndY)) >

Re: [R] Looping and paste

2011-11-23 Thread markm0705
Thank you On Thu, Nov 24, 2011 at 7:31 AM, B77S [via R] < ml-node+s789695n4102066...@n4.nabble.com> wrote: > out <- vector("list") > Ylab <- for(i in 1:length(BndY)) > { > out[i] <- paste(BndY[i]," to ",BndY[i],"mN") > } > > Ylab <- do.call(c, out) > > > > > > markm0705 wrote > Dear R helpers >

Re: [R] Looping and paste

2011-11-23 Thread R. Michael Weylandt
Try this instead: Ylab <- paste(BndY, BndY+50, "mN") Michael On Wed, Nov 23, 2011 at 5:26 PM, markm0705 wrote: > Dear R helpers > > I'm trying to make up some labels for plot from this vector > > BndY<-seq(from = 18900,to= 19700, by = 50) > > using > > Ylab<-for(i in BndY) {c((paste(i," to ",i+

[R] Looping and paste

2011-11-23 Thread markm0705
Dear R helpers I'm trying to make up some labels for plot from this vector BndY<-seq(from = 18900,to= 19700, by = 50) using Ylab<-for(i in BndY) {c((paste(i," to ",i+50,"mN")))} but the vector created is NULL However if i use for(i in BndY) {print(c(paste(i," to ",i+50,"mN")))} I can see th

Re: [R] Looping and paste

2011-11-23 Thread Bert Gunter
... and you can of course do the assignment: Bndy <- paste (BndY,"to",50+seq_len(BndY), "mN", sep = " ") "An Introduction to R" tells you about such fundamentals and should be a first read for anyone learning R. --- Bert On Wed, Nov 23, 2011 at 4:10 PM, Bert Gunter wrote: > Don't do this!  pa

Re: [R] Looping and paste

2011-11-23 Thread Bert Gunter
Don't do this! paste() is vectorized. paste (BndY,"to",50+seq_len(BndY), "mN", sep = " ") Cheers, Bert On Wed, Nov 23, 2011 at 3:31 PM, B77S wrote: > out <- vector("list") > Ylab <- for(i in 1:length(BndY)) > { > out[i] <- paste(BndY[i]," to ",BndY[i],"mN") > } > > Ylab <- do.call(c, out) > >

Re: [R] Looping and paste

2011-11-23 Thread B77S
out <- vector("list") Ylab <- for(i in 1:length(BndY)) { out[i] <- paste(BndY[i]," to ",BndY[i],"mN") } Ylab <- do.call(c, out) markm0705 wrote > > Dear R helpers > > I'm trying to make up some labels for plot from this vector > > BndY<-seq(from = 18900,to= 19700, by = 50) > > using >