When I aggregate a data frame like below I notice that some of the aggregated by column values are getting dropped
set.seed(100)
b <- data.frame(id=sample(1:3, 5, replace=TRUE),
prop1=sample(c(TRUE,FALSE),5, replace = TRUE),
prop2= sample(c(TRUE,FALSE,NA), 5, replace= TRUE))
> b
id prop1 prop2
1 3 FALSE TRUE
2 1 FALSE NA
3 2 FALSE NA
4 2 FALSE FALSE
5 3 TRUE TRUE
> aggregate(. ~ id, b, function(x) { length(x[x == TRUE])/length(x)})
id prop1 prop2
1 2 0.0 0
2 3 0.5 1
What happened to id
1 here - why is it dropped ?