Using this sample data :
filteredUS <- structure(list(Orientation.1 = c(0L, 0L, 10L, 12L, 16L, 16L,
18L, 20L, 30L, 34L, 38L, 48L, 50L, 99L, 102L, 102L, 115L, 115L,
266L, 288L, 289L, 289L, 290L, 310L, 310L, 312L, 312L, 318L, 320L,
324L, 328L, 332L, 332L, 332L, 332L, 332L, 332L, 334L, 334L, 334L,
340L)), class = "data.frame", row.names = c(NA, -41L), .Names = "Orientation.1")
I want to conserve all counted value when i cut a dataframe using factor, like table do : table(cut(filteredUS$Orientation.1, breaks = breaksVal, right = FALSE ))
Now i want the same behaviour with a dataframe which contain value for each factor using group_by
method of dplyr, is it possible ?
breaksVal <- c(seq(0, 360, by = 20), Inf)
filteredUS$levels <- cut(filteredUS$Orientation.1, breaks = breaksVal, right = FALSE )
filteredUS %>% group_by(levels) %>% summarize(n())
You can observe the result bottom :
levels n()
(fctr) (int)
1 [0,20) 7
2 [20,40) 4
3 [40,60) 2
4 [80,100) 1
5 [100,120) 4
6 [260,280) 1
7 [280,300) 4
8 [300,320) 5
9 [320,340) 12
10 [340,360) 1
I also want to conserve in my original dataframe all values, like this !
levels n()
(fctr) (int)
[0,20) 7
[20,40) 4
[40,60) 2
[60,80) 0
[80,100) 1
[100,120) 4
[120,140) 0
[140,160) 0
[160,180) 0
[180,200) 0
[200,220) 0
[220,240) 0
[240,260) 0
[260,280) 1
[280,300) 4
[300,320) 5
[320,340) 12
[340,360) 1