[R] grouping question

jim holtman jholtman at gmail.com
Sat Oct 30 03:31:57 CEST 2010


try this:

> x
 [1]  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
> y <- cut(x, breaks=c(-Inf,6,18, Inf), labels=c('a','b','c'))
> levels(y) <- c('night','day','night')
> y
 [1] night night night night night night night day   day   day   day
day   day   day   day   day   day   day
[19] day   night night night night night night
Levels: night day
>


On Fri, Oct 29, 2010 at 8:56 PM, will phillips <will.phillips at q.com> wrote:
>
> Hello
>
> I have what is probably a very simple grouping question however, given my
> limited exposure to R, I have not found a solution yet despite my research
> efforts and wild attempts at what I thought "might" produce some sort of
> result.
>
> I have a very simple list of integers that range between 1 and 24.  These
> correspond to hours of the day.
>
> I am trying to create a grouping of Day and Night with
> Day = 6 to 17.99
> Night = 1 to 5.59  and  18 to 24
>
> Using the Cut command I can create the segments but I have not found a
> "combine" type of command to merger the two "night" segments.  No luck with
> if/else either.
>
> Any help would be greatly appreciated
>
> Thank you
>
> Will
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019922.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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list