I have a data frame with following variables. The real data is values of whole month.
tripData.starttime tripData.gender
1 1/1/2016 00:00:41 1
2 1/1/2016 00:00:45 1
3 1/1/2016 00:00:48 2
4 1/1/2016 00:01:06 2
5 1/1/2016 00:01:12 1
6 1/1/2016 00:01:19 1
I am trying to group by date. For that I have done substr of date :
temp$starttime <- substr(temp$starttime,1,9)
With the above function I can only get Ymd from date
I want to count number of males and females on each day with below function I am getting count of all the males
(nrow(data[data$gender == "1", ]))
The output should be :
Date Male Female
1/1/2016 238 987
1/2/2016 554 210
1/3/2016 443 334
Also tried :
agg.count <- aggregate(day(DT$starttime) ~ DT$gender*DT$starttime, DT, FUN="length")
The output is :
DT$gender DT$starttime day(DT$starttime)
1 0 2016-01-01 2524
2 1 2016-01-01 6322
3 2 2016-01-01 2163
4 0 2016-01-02 2497
5 1 2016-01-02 8968
6 2 2016-01-02 3122