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 the for loop is making the labels I'm looking for but not sure on my error in assigning them to a vector Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4101892.html Sent from the R help mailing list archive at Nabble.com.
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 > > 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 the for loop is making the labels I'm looking for but not sure > on my error in assigning them to a vector > > Thanks in advance >-- View this message in context: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.html Sent from the R help mailing list archive at Nabble.com.
Try this instead: Ylab <- paste(BndY, BndY+50, "mN") Michael On Wed, Nov 23, 2011 at 5:26 PM, markm0705 <markm0705 at gmail.com> 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+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 the for loop is making the labels I'm looking for but not sure on > my error in assigning them to a vector > > Thanks in advance > > -- > View this message in context: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4101892.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.