Re: [R] Creating Enumerated Variables

2010-07-16 Thread Gabor Grothendieck
On Thu, Jul 15, 2010 at 10:45 AM, jdellava wrote: > > Hi, > > I am trying to create a variable counting the number of individuals based on > two variables. I am able to do it or one variable, but not two. In SAS I was > able to sort by two variables and use a first. statement to create the > count

Re: [R] Creating Enumerated Variables

2010-07-16 Thread Dennis Murphy
Hi: Hadley's solution is certainly preferred here due to its relative simplicity. I just wanted to correct an error from my earlier post. On Thu, Jul 15, 2010 at 2:08 PM, Dennis Murphy wrote: > Hi: > > I sincerely hope there's an easier way, but one method to get this is as > follows, > with d

Re: [R] Creating Enumerated Variables

2010-07-16 Thread Hadley Wickham
On Thu, Jul 15, 2010 at 11:08 PM, Dennis Murphy wrote: > Hi: > > I sincerely hope there's an easier way, but one method to get this is as > follows, > with d as the data frame name of your test data: > > d <- d[order(with(d, Age, School, rev(Grade))), ] > d$Count <- do.call(c, mapply(seq, 1, as.ve

Re: [R] Creating Enumerated Variables

2010-07-16 Thread John Kane
} ecount <- unlist(mylist) cbind(xx[order(xx[,3]),], ecount) --- On Thu, 7/15/10, Dennis Murphy wrote: > From: Dennis Murphy > Subject: Re: [R] Creating Enumerated Variables > To: "jdellava" > Cc: r

Re: [R] Creating Enumerated Variables

2010-07-15 Thread Dennis Murphy
Hi: I sincerely hope there's an easier way, but one method to get this is as follows, with d as the data frame name of your test data: d <- d[order(with(d, Age, School, rev(Grade))), ] d$Count <- do.call(c, mapply(seq, 1, as.vector(t(with(d, table(Age, School)) d > d ID Age School Grade Co

Re: [R] Creating Enumerated Variables

2010-07-15 Thread Wu Gong
If you only want a count, please try table text <- "ID Age School Grade 1 10 1 98 2 10 2 97 3 10 1 92 4 11 1 90 5 11 1 80 6 11 2 70 7 10 1 80 8 10 1 79 9 11 2 70" df <- read.table(textConnection(text),header=T) table(df[,2:3]) If you want sort the data, try order. - A R learner. -- View t

[R] Creating Enumerated Variables

2010-07-15 Thread jdellava
Hi, I am trying to create a variable counting the number of individuals based on two variables. I am able to do it or one variable, but not two. In SAS I was able to sort by two variables and use a first. statement to create the counts based on both. Here is an example: What I have ID Age