Skip to content
Prev 305677 / 398506 Next

count NAs per week

HI,
May be this is what you wanted.
?res1<-aggregate(dattrial2$a,list(dattrial2$Week,dattrial2$AnimalID),function(x) sum(is.na(x)))
#$Bert
#? Group.1 Group.2 x
#1?????? 3??? Bert 1
#2?????? 4??? Bert 1

#$Ernie
?# Group.1 Group.2 x
#3?????? 3?? Ernie 1
#4?????? 4?? Ernie 0


A.K.



----- Original Message -----
From: Tagmarie <Ramgad82 at gmx.net>
To: r-help at r-project.org
Cc: 
Sent: Monday, September 17, 2012 9:07 AM
Subject: Re: [R] count NAs per week

Thank you Michael, that worked perfectly! 

Now I wonder, if it is possible to break my data further apart and put it
together again. 
Assume I include a column for an ID in the data frame like this: 

dattrial2<-data.frame(a=c(1,NA,NA,NA,2,3), Week=c(3,3,3,4,4,4),
AnimalID=c("Ernie","Bert", "Ernie", "Bert", "Bert", "Ernie"))

Is it possible to get two different lists in the output, one for Ernie and
one for Bert? Or do I have to do it seperately for each animal?

Thank you again! I learn a lot by doing and by people helping me. Thank you
for the hint with the paper. 





--
View this message in context: http://r.789695.n4.nabble.com/count-NAs-per-week-tp4643351p4643371.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.