c(1, 2, 3, 4, 8, 2, 3))
> last.record(df, "Name", "Value")
> last.record(df, 1, 2)
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Hao Cen
Sent: Monday, November 16, 2009 2:43 PM
To: r-help@r-project.org
Subjec
Thanks to all who helped. These are all great suggestions.
Jeff
-Original Message-
From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
Sent: Monday, November 16, 2009 6:27 PM
To: Hao Cen
Cc: r-help@r-project.org
Subject: Re: [R] extracting the last row of each group in a data
Try this:
> aggregate(DF[-1], DF[1], tail, 1)
Name Value
1A 3
2B 8
3C 2
4D 3
On Mon, Nov 16, 2009 at 2:42 PM, Hao Cen wrote:
> Hi,
>
> I would like to extract the last row of each group in a data frame.
>
> The data frame is as follows
>
> Name Value
> A 1
> A
I would use pkg:plyr, but just to show how
versatile R is:
ind <- cumsum(rle(as.numeric(dat$Name))$lengths)
dat[ind, ]
where I'm assuming that your data frame is
called 'dat'.
-Peter Ehlers
Hao Cen wrote:
Hi,
I would like to extract the last row of each group in a data frame.
The data fram
jeffc wrote:
>
> Hi,
>
> I would like to extract the last row of each group in a data frame.
>
> The data frame is as follows
>
> Name Value
> A 1
> A 2
> A 3
> B 4
> B 8
> C 2
> D 3
>
> I would like to get a data frame as
> Name Value
> A 3
> B 8
> C 2
> D 3
>
> Thank you for your suggesti
Dear Jeff,
Here is a suggestion using tapply:
data.frame(last = with(x, tapply(Value, Name, function(x) x[length(x)])))
See ?tapply for more information.
HTH,
Jorge
On Mon, Nov 16, 2009 at 2:42 PM, Hao Cen <> wrote:
> Hi,
>
> I would like to extract the last row of each group in a data frame
On Nov 16, 2009, at 2:42 PM, Hao Cen wrote:
Hi,
I would like to extract the last row of each group in a data frame.
The data frame is as follows
Name Value
A 1
A 2
A 3
B 4
B 8
C 2
D 3
by(dfname$Value, dfname$Name, tail, 1) #which gets you a list
Or:
aggregate(dfname$Value, list(dfname$N
Hi,
You could try plyr,
library(plyr)
ddply(d,.(Name), tail,1)
Name Value
1A 3
2B 8
3C 2
4D 3
HTH,
baptiste
2009/11/16 Hao Cen :
> Hi,
>
> I would like to extract the last row of each group in a data frame.
>
> The data frame is as follows
>
> Name Value
> A
Hi,
I would like to extract the last row of each group in a data frame.
The data frame is as follows
Name Value
A 1
A 2
A 3
B 4
B 8
C 2
D 3
I would like to get a data frame as
Name Value
A 3
B 8
C 2
D 3
Thank you for your suggestions in advance
Jeff
__
9 matches
Mail list logo