[R] number of individuals where X=0 during all periods (longitudinal data)
Chel Hee Lee
chl948 at mail.usask.ca
Mon Dec 22 19:54:01 CET 2014
> tmp <- split(Test, Test$ID)
> # number of subjects with X=0 (all periods)
> x <- lapply(tmp, function(x) all(x$X ==0))
> # number of subjects with X=0 (at least three weeks)
> x <- lapply(tmp, function(x) sum(x$X==0)>=3)
Is this what you are looking for? I hope this helps.
Chel Hee Lee
On 12/22/2014 7:45 AM, najuzz wrote:
> #Hi guys,
> #I would like to count the number of individuals that receive X=0 troughout
> their observational period.
> #example dataset:
> # Individuals 2 and 3 have x=0 during all their periods. The count should
> hence equal to two. I simply have
> # no clue how R could solve this for me. As an addon, I would also like to
> know the number of individuals #that report X=0 during all periods plus
> have at least 3 weeks of observations. The answer would be one in #this
> sample datset.
> #Thank you
> View this message in context: http://r.789695.n4.nabble.com/number-of-individuals-where-X-0-during-all-periods-longitudinal-data-tp4701023.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help