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
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
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
}
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
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
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
6 matches
Mail list logo