I have a tibble like this.
# A tibble: 200,000 × 3
Steps Distance run
<int> <dbl> <chr>
1 1000 33.32683 0
2 2000 35.02510 0
3 3000 36.19157 0
4 4000 37.82663 0
5 5000 36.30477 0
6 6000 37.78146 0
7 7000 38.62345 0
8 8000 34.84085 0
9 9000 37.05461 0
10 10000 43.02439 0
11 10000 44.12345 1
I want to use a group_by of "run". Then bin the value in to a specific number of bins. To make something like this.
run Interval Count
0 0-10 xx
0 10-100 xx
1 0-10 xx
I found out a similar function like "bin_data", but it's not compatible with group_by.
Thank you.
You can bin the data first, then use summarize and n to count the number of observations in each group.
data_frame(Group = sample(letters[1:2],20,replace = T),Value=runif(20,0,5)) %>%
mutate(Bin = cut(Value,breaks = 0:5)) %>%
group_by(Group,Bin) %>%
summarise(Count = n())
Source: local data frame [8 x 3]
Groups: Group [?]
Group Bin Count
<chr> <fctr> <int>
1 a (0,1] 1
2 a (1,2] 6
3 a (2,3] 2
4 a (4,5] 4
5 b (0,1] 1
6 b (1,2] 2
7 b (3,4] 2
8 b (4,5] 2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.