[R] group data based on row value

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Thu May 23 00:26:44 CEST 2013


dat$group <- cut( dat$Var, breaks=c(-Inf,0.1, 0.6,Inf))
levels(dat$group) <- LETTERS[1:3]

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Ye Lin <yelin at lbl.gov> wrote:

>hey, I want to divide my data into three groups based on the value in
>one
>column with group name.
>
>dat:
>
>Var
>0
>0.2
>0.5
>1
>4
>6
>
>I tried:
>
>dat <- cbind(dat, group=cut(dat$Var, breaks=c(0.1,0.6)))
>
>But it doesnt work, I want to group those <0.1 as group A, 0.1-0.6 as
>group
>B, >0.6 as group C
>
>Thanks for your help!
>
>	[[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.



More information about the R-help mailing list