Re: [R] Value between which elements of a vector?

From: andrija djurovic <djandrija_at_gmail.com>
Date: Tue, 05 Apr 2011 15:33:04 +0200

Hi:

try this and have a look at ?cut just to change the lables:

data.frame(
weeks=sprintf('%s %d','week',1:30),
specialweeks=cut(1:30,c(0,2,5,12,18,19,20),right = FALSE))

Andrija

On Tue, Apr 5, 2011 at 1:20 PM, beatleb <rhelpforum_at_gmail.com> wrote:

> Dear R-useRs,
>
> I am looking for a why to perform the following:
>
> specialweeks<-c(0,2,5,12,18,19,20)
> weeks<-c(1:30)
>
> Now I would like that for every week it is even between which elements of
> vector special weeks it is.
> For weeks after 20, the value NA or 20, or even 20-30is fine.
>
> Thus for
> week 1: 0-2
> week 2: 2-5
> week 3: 2-5
> week 4: 2-5
> week 5: 5-12
> ect....
>
> It is not relevant if those intervals are captured in a matrix, in a vector
> or whatever.
>
> I hope that you can help me!
>
> With best regards,
>
> Brenda Grondman
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Value-between-which-elements-of-a-vector-tp3427751p3427751.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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]



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. Received on Tue 05 Apr 2011 - 13:36:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Apr 2011 - 13:40:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive