On Thursday, May 07, 2009 7:45 PM, David Freedman wrote:
...how about:
d=data[order(data$ID,-data$Type),]
d[!duplicated(d$ID),]
Does the -data$Type argument to the order function work?
--
David
-
David Huffer, Ph.D.
sorry about the mistake - the -data$Type doesn't work: the '-' sign isn't
valid for factors. I *thought* I had checked this before submitting a
response !
HufferD wrote:
On Thursday, May 07, 2009 7:45 PM, David Freedman wrote:
...how about:
d=data[order(data$ID,-data$Type),]
This is a problem much like the one I had a few weeks ago. David's solution
is more concise. Try xtfrm() or rank() for factor sorting
d=data[order(data$ID,-xtfrm(data$Type)),] should work. By the way I got it
from Duncan.
Jun
On Fri, May 8, 2009 at 4:09 PM, David Freedman 3.14da...@gmail.com
On Wed, May 6, 2009 at 8:12 PM, jim holtman jholt...@gmail.com wrote:
Ths should do it:
do.call(rbind, lapply(split(x, x$ID), tail, 1))
ID Type N
45900 45900 I 7
46550 46550 I 7
49270 49270 E 3
Or with plyr:
library(plyr)
ddply(x, id, tail, 1)
plyr encapsulates the
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Max Webber
Sent: Wednesday, May 06, 2009 3:09 PM
To: r-help@r-project.org
Subject: [R] by-group processing
Given
how about:
d=data[order(data$ID,-data$Type),]
d[!duplicated(d$ID),]
Max Webber wrote:
Given a dataframe like
data
ID Type N
1 45900A 1
2 45900B 2
3 45900C 3
4 45900D 4
5 45900E 5
6 45900F 6
7 45900I 7
8 49270A 1
Dear Max,
By using d instead of data for your data set, here is one way:
# First order the data by ID
d - with(d, d[order(ID),] )
# Then use tapply to get the indexes for the maximum values
d[cumsum(with(d, tapply(N, ID, which.max))),]
# ID Type N
# 7 45900I 7
# 24 46550I 7
# 10 49270
Ths should do it:
do.call(rbind, lapply(split(x, x$ID), tail, 1))
ID Type N
45900 45900I 7
46550 46550I 7
49270 49270E 3
On Wed, May 6, 2009 at 6:09 PM, Max Webber ubber...@gmail.com wrote:
Given a dataframe like
data
ID Type N
1 45900A 1
2 45900
8 matches
Mail list logo