I 'd like to get the number and percent of cases that meet a certain condition , grouped by another column.
The groups are the cities, the condition is hour >= 6
.
For example
city hour
A 7
A 6
A 3
B 2
C 7
I'd like to get
city hour>=6
A 2
B 1
C 0
and than every percentage based on cases by city.
city hours >= 6 (%)
A 0.6666667
B 1.0000000
C 0.0000000
City --- hour
I think I'm almost there
aggregate(hours, list(city), mean)
I get the mean of hour by city but I don't understand how to get the other results.
MG