An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091125/62ecd9aa/attachment-0001.pl>
Unique observations
3 messages · John Lipkins, jim holtman, David Winsemius
shouldn't the first observation for Tree1 be " Tree1 leaves 01-01-2009"?
x <- read.table(textConnection("Tree disease date
+ Tree1 leaves 01-01-2009 + Tree2 roots 13-09-2009 + Tree1 roots 24-10-2009"), header=TRUE)
closeAllConnections()
# split by "Tree" and take first observation
do.call('rbind', lapply(split(x, x$Tree), function(.tr) .tr[1,]))
Tree disease date Tree1 Tree1 leaves 01-01-2009 Tree2 Tree2 roots 13-09-2009
On Wed, Nov 25, 2009 at 9:44 AM, John Lipkins
<john.lipkins at googlemail.com> wrote:
Hey R list, A beginners question. How can I do the following: In my research population it is possible that several items can appear several times, measured on different moments in time. This is being supplied in a total list with all observations identified by a number (per item) and a moment of observation (date). Now I want to make a unique list of this observation preserving the characteristics of the first observation. As example: ?Tree ?disease ?date ?Tree1 ?leaves ?01-01-2009 ?Tree2 ?roots ?13-09-2009 ?Tree1 ?roots ?24-10-2009 Now I want to create a list of unique elements (in the example only once Tree1 and Tree2) with the first observed disease and date. For the example the result would look like: ?Tree ?disease ?date ?Tree1 ?roots ?24-10-2008 ?Tree2 ?roots ?13-09-2009 Can someone help me with this question? Thanks in advance. Kind regards, John ? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
On Nov 25, 2009, at 9:44 AM, John Lipkins wrote:
Hey R list, A beginners question. How can I do the following: In my research population it is possible that several items can appear several times, measured on different moments in time. This is being supplied in a total list with all observations identified by a number (per item) and a moment of observation (date). Now I want to make a unique list of this observation preserving the characteristics of the first observation. As example: Tree disease date Tree1 leaves 01-01-2009 Tree2 roots 13-09-2009 Tree1 roots 24-10-2009 Now I want to create a list of unique elements (in the example only once Tree1 and Tree2) with the first observed disease and date. For the example the result would look like: Tree disease date Tree1 roots 24-10-2008 Tree2 roots 13-09-2009 Can someone help me with this question?
I think the function you will need include: ?as.Date #to get the date field into sortable form ?order #as in treedat2 <- treedat[ order(treedat$dt, treedat$Tree), ] ?duplicated # as in treedat2[ !duplicated(treedat2(Tree), ] -- David Winsemius, MD Heritage Laboratories West Hartford, CT