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
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))
>
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
>
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+
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
... 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
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)
>
>
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
>
8 matches
Mail list logo