s-news
[Top] [All Lists]

Re: how to extract entire rows from a data frame based on a index

To: "Schwarz,Paul" <PSchwarz@gcrinsight.com>
Subject: Re: how to extract entire rows from a data frame based on a index
From: David L Lorenz <lorenz@usgs.gov>
Date: Thu, 17 Nov 2005 07:26:15 -0600
Cc: s-news@lists.biostat.wustl.edu, s-news-owner@lists.biostat.wustl.edu
In-reply-to: <89C7DEAADB79564DB278694EB2417CCE5FAA3C@CHOCOLATE.GCRInsight.com>

Paul,
  The aggregate() function should do what you want. Look at the aggregate.data.frame() documentation. The data would need to be sorted by date or ID and date to work correctly.
Dave


"Schwarz,Paul" <PSchwarz@gcrinsight.com>
Sent by: s-news-owner@lists.biostat.wustl.edu

11/17/2005 01:11 AM

To
<s-news@lists.biostat.wustl.edu>
cc
Subject
[S] how to extract entire rows from a data frame based on a index variable?





Dear S-News readers,

I'm puzzling over how to solve the following problem. Let's say that I
have a data frame with possibly multiple observations (rows) per
sampling unit, in this case survey respondents. In addition to a
respondent ID variable, there is a date variable tracking the date the
information was collected. If I want to extract from this data frame
only the most recent observation (or the first, etc.) for each
respondent, how could I do this? I've been thinking about this problem
as a tapply()-like problem where the respondent ID would be the index
variable, but I haven't figured how to write a function to extract and
return entire rows. I would appreciate ideas or suggestions from fellow
list readers on how to solve this.

Thanks for your help.

-Paul
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>