This is my data:
> head(Kandula_for_n)
date dist date_only
1 2005-05-08 12:00:00 138.5861 2005-05-08
2 2005-05-08 16:00:00 1166.9265 2005-05-08
3 2005-05-08 20:00:00 1270.7149 2005-05-08
6 2005-05-09 08:00:00 233.1971 2005-05-09
7 2005-05-09 12:00:00 1899.9530 2005-05-09
8 2005-05-09 16:00:00 726.8363 2005-05-09
我现在要增加一个,每个数据条目(dist)的(n)项。 2005-05-08年度数据为零,因为12、16和20小时有3个数据条目。 我采用了以下法典,实际上使我想到的是:
ndist <-tapply(1:NROW(Kandula_for_n), Kandula_for_n$date_only, function(x) length(unique(x)))
在ndist<-as.data.frame(ndist)
之后,我接着说:
> head(ndist)
ndist
2005-05-08 3
2005-05-09 4
2005-05-10 6
2005-05-11 4
2005-05-12 6
2005-05-13 6
The problem is that the count is together with date_only in one column that is called ndist. But I would need them in two separate columns, one with the count and one with date_only. How can this be done? I guess its rather simple, but I just don t get it. I would appreciate if you could give me any thoughts on that.
感谢您的努力。