Looping and paste

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Looping and paste

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 loop is making the labels I'm looking for but not sure on my error in assigning them to a vector

Thanks in advance
Mark Murphy
Technical Director Mining and Geology
AMEC Perth WA
Reply | Threaded
Open this post in threaded view
|

Re: Looping and paste

Brad Schneid
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
Reply | Threaded
Open this post in threaded view
|

Re: Looping and paste

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 <[hidden email]> 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 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.
>
> ______________________________________________
> [hidden email] 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.
>



--

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and paste

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 <[hidden email]> wrote:

> 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 <[hidden email]> 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 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.
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>



--

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and paste

markm0705
In reply to this post by Brad Schneid
Thank you

On Thu, Nov 24, 2011 at 7:31 AM, B77S [via R] <[hidden email]> 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 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



If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.html
To unsubscribe from Looping and paste, click here.
NAML

Mark Murphy
Technical Director Mining and Geology
AMEC Perth WA
Reply | Threaded
Open this post in threaded view
|

Re: Looping and paste

markm0705
In reply to this post by Brad Schneid
And thanks fo rthe pointer to the R introduction book as well

On Thu, Nov 24, 2011 at 11:00 AM, Mark Murphy <[hidden email]> wrote:
Thank you


On Thu, Nov 24, 2011 at 7:31 AM, B77S [via R] <[hidden email]> 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 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



If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.html
To unsubscribe from Looping and paste, click here.
NAML


Mark Murphy
Technical Director Mining and Geology
AMEC Perth WA
Reply | Threaded
Open this post in threaded view
|

Re: Looping and paste

Michael Weylandt
In reply to this post by markm0705
Try this instead:

Ylab <- paste(BndY, BndY+50, "mN")

Michael

On Wed, Nov 23, 2011 at 5:26 PM, markm0705 <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and paste

djmuseR
In reply to this post by markm0705
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 + 50, ' mN', sep = '')

# Loop version:
m2 <- function(v) {
      out <- rep(NA, length(v))
      for(i in seq_along(v)) out[i] <- paste(v[i], ' to ', v[i] + 50,
' mN', sep = '')
      out
    }
BndY <- seq(from = 18900, to = 19700, by = 50)

> identical(m1(BndY), m2(BndY))
[1] TRUE

# Put them to the test:
> system.time(replicate(10000, m1(BndY)))
   user  system elapsed
   0.67    0.00    0.67
> system.time(replicate(10000, m2(BndY)))
   user  system elapsed
   2.67    0.00    2.67

The vectorized version is four times faster and produces the same
output as the loop version. Experiments with a longer test vector (501
elements) maintained the timing ratio.

Dennis


On Wed, Nov 23, 2011 at 7:00 PM, markm0705 <[hidden email]> wrote:

> Thank you
>
> On Thu, Nov 24, 2011 at 7:31 AM, B77S [via R] <
> [hidden email]> 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 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
>>
>>
>>
>> ------------------------------
>>  If you reply to this email, your message will be added to the discussion
>> below:
>> http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.html
>> To unsubscribe from Looping and paste, click here<
>> .
>> NAML<
http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespace&breadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102553.html
> Sent from the R help mailing list archive at Nabble.com.
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

First read (was: Re: Looping and paste)

Patrick Burns
In reply to this post by Bert Gunter
It's very seldom that I disagree with
Bert, but here is one time.

I don't think "An Introduction to R" is
a suitable first read for people with
little computational experience.

Better (I modestly suggest) would be:

http://www.burns-stat.com/pages/Tutor/hints_R_begin.html

which includes some other references.
'Hints' is imperfect and incomplete but
it suffers slightly less from the curse of
knowledge than a lot of other R documentation.

Pat

On 24/11/2011 00:15, Bert Gunter wrote:

> ... 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<[hidden email]>  wrote:
>> 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<[hidden email]>  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 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.
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>>
>>
>>
>>
>> --
>>
>> Bert Gunter
>> Genentech Nonclinical Biostatistics
>>
>> Internal Contact Info:
>> Phone: 467-7374
>> Website:
>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>>
>
>
>

--
Patrick Burns
[hidden email]
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: First read (was: Re: Looping and paste)

Liviu Andronic
On Thu, Nov 24, 2011 at 9:27 AM, Patrick Burns <[hidden email]> wrote:
> It's very seldom that I disagree with
> Bert, but here is one time.
>
> I don't think "An Introduction to R" is
> a suitable first read for people with
> little computational experience.
>
I must agree with Patrick here. The 'Intro to R' may be appropriate
for someone already versed in statistics and/or programming, but it is
hardly useful as a first read for the neophytes.


> Better (I modestly suggest) would be:
>
> http://www.burns-stat.com/pages/Tutor/hints_R_begin.html
>
To chip in, the first two chapters of Fox and Weisberg (2011) make for
an excellent introduction to R programming. It's gentle, but also
covers many of the difficulties and misunderstandings that one would
encounter in R.

Regards
Liviu




> which includes some other references.
> 'Hints' is imperfect and incomplete but
> it suffers slightly less from the curse of
> knowledge than a lot of other R documentation.
>
> Pat
>
> On 24/11/2011 00:15, Bert Gunter wrote:
>>
>> ... 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<[hidden email]>  wrote:
>>>
>>> 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<[hidden email]>  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 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.
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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.
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Bert Gunter
>>> Genentech Nonclinical Biostatistics
>>>
>>> Internal Contact Info:
>>> Phone: 467-7374
>>> Website:
>>>
>>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>>>
>>
>>
>>
>
> --
> Patrick Burns
> [hidden email]
> twitter: @portfolioprobe
> http://www.portfolioprobe.com/blog
> http://www.burns-stat.com
> (home of 'Some hints for the R beginner'
> and 'The R Inferno')
>
> ______________________________________________
> [hidden email] 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.
>



--
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: First read (was: Re: Looping and paste)

Bert Gunter
In reply to this post by Patrick Burns
Pat:

1. Thank you for this. Having not read your tutorial, but based on
what I know of your other efforts, I am sure that you are correct. Is
there a link to this on CRAN somewhere so I can refer to it in future
(too lazy to search myself)?

2. Thank you also for your continuing contributions to R
documentation. I know this takes a lot of work and you do it well.
Would that more R learners would read them -- there would be a lot
less "RTFM" type queries on r-help.

Best,
Bert

On Thu, Nov 24, 2011 at 12:27 AM, Patrick Burns
<[hidden email]> wrote:

> It's very seldom that I disagree with
> Bert, but here is one time.
>
> I don't think "An Introduction to R" is
> a suitable first read for people with
> little computational experience.
>
> Better (I modestly suggest) would be:
>
> http://www.burns-stat.com/pages/Tutor/hints_R_begin.html
>
> which includes some other references.
> 'Hints' is imperfect and incomplete but
> it suffers slightly less from the curse of
> knowledge than a lot of other R documentation.
>
> Pat
>
> On 24/11/2011 00:15, Bert Gunter wrote:
>>
>> ... 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<[hidden email]>  wrote:
>>>
>>> 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<[hidden email]>  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 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.
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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.
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Bert Gunter
>>> Genentech Nonclinical Biostatistics
>>>
>>> Internal Contact Info:
>>> Phone: 467-7374
>>> Website:
>>>
>>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>>>
>>
>>
>>
>
> --
> Patrick Burns
> [hidden email]
> twitter: @portfolioprobe
> http://www.portfolioprobe.com/blog
> http://www.burns-stat.com
> (home of 'Some hints for the R beginner'
> and 'The R Inferno')
>
> ______________________________________________
> [hidden email] 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.
>



--

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: First read

Patrick Burns
Bert,

Your laziness is well founded -- it
is not on CRAN, you have to go all
the way over to another website.

And thanks for the kind words (even
though we Europeans are free to be
ingrates today).

Pat

On 24/11/2011 14:23, Bert Gunter wrote:

> Pat:
>
> 1. Thank you for this. Having not read your tutorial, but based on
> what I know of your other efforts, I am sure that you are correct. Is
> there a link to this on CRAN somewhere so I can refer to it in future
> (too lazy to search myself)?
>
> 2. Thank you also for your continuing contributions to R
> documentation. I know this takes a lot of work and you do it well.
> Would that more R learners would read them -- there would be a lot
> less "RTFM" type queries on r-help.
>
> Best,
> Bert
>
> On Thu, Nov 24, 2011 at 12:27 AM, Patrick Burns
> <[hidden email]>  wrote:
>> It's very seldom that I disagree with
>> Bert, but here is one time.
>>
>> I don't think "An Introduction to R" is
>> a suitable first read for people with
>> little computational experience.
>>
>> Better (I modestly suggest) would be:
>>
>> http://www.burns-stat.com/pages/Tutor/hints_R_begin.html
>>
>> which includes some other references.
>> 'Hints' is imperfect and incomplete but
>> it suffers slightly less from the curse of
>> knowledge than a lot of other R documentation.
>>
>> Pat
>>
>> On 24/11/2011 00:15, Bert Gunter wrote:
>>>
>>> ... 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<[hidden email]>    wrote:
>>>>
>>>> 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<[hidden email]>    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 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.
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] 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.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Bert Gunter
>>>> Genentech Nonclinical Biostatistics
>>>>
>>>> Internal Contact Info:
>>>> Phone: 467-7374
>>>> Website:
>>>>
>>>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>>>>
>>>
>>>
>>>
>>
>> --
>> Patrick Burns
>> [hidden email]
>> twitter: @portfolioprobe
>> http://www.portfolioprobe.com/blog
>> http://www.burns-stat.com
>> (home of 'Some hints for the R beginner'
>> and 'The R Inferno')
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
>
>

--
Patrick Burns
[hidden email]
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

______________________________________________
[hidden email] 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.