Re: [R] Unique observations
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 __ R-help@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.
Re: [R] Unique observations
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 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@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? __ R-help@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.
[R] Unique observations
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@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.