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 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 Ylab-for(i in

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 bps0...@auburn.edu 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 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 bgun...@gene.com wrote: Don't do

[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 the for

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 markm0...@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

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 I'm trying to make up

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 markm0...@gmail.com 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

Re: [R] looping with paste

2011-08-26 Thread Juta Kawalerowicz
: Re: [R] looping with paste As Sarah has said, you probably don't need to use paste() at all. However if command is a text string containing a (syntactically correct) R command you can execute it via eval(parse(text=command)) E.g.: command - x - 42 eval(parse(text=command

[R] looping with paste

2011-08-22 Thread Juta Kawalerowicz
Dear list, I have a spacialPolygonDataFrame where variables were unnecessarily imported as factors. So I am trying to unfactor variables from spatialPolygonDataFrame@data with a loop for (i in (1:length(names( spatialPolygonDataFrame{

Re: [R] looping with paste

2011-08-22 Thread Sarah Goslee
Juta, On Mon, Aug 22, 2011 at 4:29 PM, Juta Kawalerowicz juta.kawalerow...@stx.ox.ac.uk wrote: Dear list, I have a spacialPolygonDataFrame where variables were unnecessarily imported as factors. So I am trying to unfactor variables from spatialPolygonDataFrame@data with a loop for (i in

Re: [R] looping with paste

2011-08-22 Thread Rolf Turner
As Sarah has said, you probably don't need to use paste() at all. However if command is a text string containing a (syntactically correct) R command you can execute it via eval(parse(text=command)) E.g.: command - x - 42 eval(parse(text=command)) x [1] 42 I find this to