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

Re: [R] group data

2013-04-15 Thread arun
x1$group<- paste0("Key",i);x1}))  res #   ID Value group #1 AL1 1  Key1 #2 AL2 2  Key1 #3 CA1 3  Key2 #4 CA4 4  Key2 A.K. - Original Message - From: Ye Lin To: Rui Barradas Cc: R help Sent: Monday, April 15, 2013 11:50 AM Subject: Re: [R] group data Wha

Re: [R] group data

2013-04-15 Thread Ye Lin
What if more generally that the group name doest have anything to do with the ID, eg. for ID=AL1 and AL2, I want to name the group as "Key1", how can I approach that? Thanks, On Thu, Apr 11, 2013 at 11:54 AM, Rui Barradas wrote: > Hello, > > Try the following. > > > dat <- read.table(text = "

Re: [R] group data

2013-04-11 Thread Ye Lin
I think I just misinterpret~Thanks for your help~ On Thu, Apr 11, 2013 at 11:54 AM, Rui Barradas wrote: > Hello, > > Try the following. > > > dat <- read.table(text = " > > ID Value > AL1 1 > AL2 2 > CA1 3 > CA4 4 > ", header = TRUE, stringsAsFactors = FALSE) > > dat$State <- substr(dat$ID

Re: [R] group data

2013-04-11 Thread arun
Hi, dat1<- read.table(text=" ID  Value AL1  1 AL2  2 CA1  3 CA4  4 ",sep="",header=TRUE,stringsAsFactors=FALSE) dat2<- dat1 dat1$State<-gsub("\\d+","",dat1$ID) dat1 #   ID Value State #1 AL1 1    AL #2 AL2 2    AL #3 CA1 3    CA #4 CA4 4    CA #or library(stringr) dat2$State<-s

Re: [R] group data

2013-04-11 Thread Ye Lin
Thanks! But What if I have a very large data with 1000+rows, anyway to identify all "AL1" and "AL2" under "ID" and mark them as "AL" under new column "State"? Thanks. On Thu, Apr 11, 2013 at 11:54 AM, Rui Barradas wrote: > Hello, > > Try the following. > > > dat <- read.table(text = " > > ID

Re: [R] group data

2013-04-11 Thread Rui Barradas
Hello, Try the following. dat <- read.table(text = " ID Value AL1 1 AL2 2 CA1 3 CA4 4 ", header = TRUE, stringsAsFactors = FALSE) dat$State <- substr(dat$ID, 1, 2) Note that this dependes on having State being defined by the first two characters of ID. Hope this helps, Rui Barradas

[R] group data

2013-04-11 Thread Ye Lin
Hey, I have a dataset and I want to identify the records by groups for further use in ggplot. Here is a sample data: ID Value AL1 1 AL2 2 CA1 3 CA4 4 I want to identify all the records that in the same state (AL1 AND A2), group them as "AL", and do the same for CA1 and CA4. How can I have

Re: [R] group data in classes

2013-04-07 Thread arun
5) #  year    decade #1 1598 1590-1600 #2 1599 1590-1600 #3 1600 1590-1600 #4 1601 1600-1610 #5 1602 1600-1610 A.K. - Original Message - From: catalin roibu To: r-help@r-project.org Cc: Sent: Sunday, April 7, 2013 3:47 AM Subject: [R] group data in classes Hello all! I have a problem to

Re: [R] group data in classes

2013-04-07 Thread Rolf Turner
brs <- seq(1590,2000,by=10) lbs <- paste(brs[-length(brs)],brs[-1],sep="-") y <- cut(x,breaks=brs,labels=lbs) # Where "x" is your data vector. grpd <- data.frame(year=x,decade=y) head(grpd) yeardecade 1 1598 1590-1600 2 1599 1590-1600 3 1600 1590-1600 4 1601 1600-1610 5 1602 1600-1610 6 16

[R] group data in classes

2013-04-07 Thread catalin roibu
Hello all! I have a problem to group my data (years) in 10 years classes. For example for year year decade 1598 1590-1600 1599 1590-1600 1600 1590-1600 1601 1600-1610 --- my is like this> [1] 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 [16] 1613 1614 1615

Re: [R] Group Data indexed by n Variables

2011-07-06 Thread Paolo Rossi
Actually to get exactly what I want I need to add no.dimnames(AvgDemand ) where no.dimnames <- function(a) { ## Remove all dimension names from an array for compact printing. d <- list() l <- 0 for(i in dim(a)) { d[[l <- l + 1]] <- rep("", i) } di

[R] Group Data indexed by n Variables

2011-07-06 Thread Paolo Rossi
Hello, the more general thing I'd like to learn here is how to compute Function of Data on the basis of grouping determiend by n variables. In terms of the reason why I am interested in this, I need to compute the average of my data based on the value of the month and day across years. I have com