Re: [R] group data based on row value

2013-05-23 Thread David Carlson
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Wednesday, May 22, 2013 5:27 PM To: Ye Lin; R help Subject: Re: [R] group data based on row value dat$group <- cut( dat

Re: [R] group data based on row value

2013-05-22 Thread Jeff Newmiller
dat$group <- cut( dat$Var, breaks=c(-Inf,0.1, 0.6,Inf)) levels(dat$group) <- LETTERS[1:3] --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go...

Re: [R] group data based on row value

2013-05-22 Thread arun
Hi, Try: dat<- read.table(text=" Var 0 0.2 0.5 1 4 6 ",sep="",header=TRUE) res1<-within(dat,group<-factor(findInterval(Var,c(-Inf,0.1,0.6),rightmost.closed=TRUE),labels=LETTERS[1:3]))  res1  # Var group #1 0.0 A #2 0.2 B #3 0.5 B #4 1.0 C #5 4.0 C #6 6.0 C #or res2<-with

[R] group data based on row value

2013-05-22 Thread Ye Lin
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 fo