总结日期数据我想下面的示例数据聚合成一个新的数据帧,如下所示:如何通过基团中的R
人口,样本大小(N),完成的百分比(%)
样品大小是每个人口的所有记录的计数。我可以使用table命令或tapply来做到这一点。完成百分比是与“结束日期的(不包括所有记录‘终止日期’被假定为不完整记录的百分比,这是我输了!
样本数据
sample <- structure(list(Population = structure(c(1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 3L, 3L), .Label = c("Glommen",
"Kaseberga", "Steninge"), class = "factor"), Start_Date = structure(c(16032,
16032, 16032, 16032, 16032, 16036, 16036, 16036, 16037, 16038,
16038, 16039, 16039, 16039, 16039, 16039, 16039, 16041, 16041,
16041, 16041, 16041, 16041, 16044, 16044, 16045, 16045, 16045,
16045, 16048, 16048, 16048, 16048, 16048, 16048), class = "Date"),
End_Date = structure(c(NA, 16037, NA, NA, 16036, 16043, 16040,
16041, 16042, 16042, 16042, 16043, 16043, 16043, 16043, 16043,
16043, 16045, 16045, 16045, 16045, 16045, NA, 16048, 16048,
16049, 16049, NA, NA, 16052, 16052, 16052, 16052, 16052,
16052), class = "Date")), .Names = c("Population", "Start_Date",
"End_Date"), row.names = c(NA, 35L), class = "data.frame")
对不起数据框名称。我试图保持简单。我很欣赏使用基本功能的解决方案。我有一个更复杂的问题,你的解决方案帮我弄明白了。 –