I have following dataframe in R
ID Blocks
123 2D
345 2E
324 2D
567 4F
678 5E
444 2D
145 2D
Now I want to subset dataframe based on a vector and then on each subset I want to apply group by
e.g vec <- c(2,3,2)
Now First it should subset the dataframe with first two rows
df <- df[1:2,]
df %>%
group_by(Blocks) %>%
summarise(count = n())
Then it should subset the dataframe with next 3 rows
df <- df[3:5,]
df %>%
group_by(Blocks) %>%
summarise(count = n())
and so on. Desired output will be,
Subset 2D 2E 4F 5E
2 1 1 0 0
3 1 0 1 1
2 2 0 0 0
Individually I can do with above code,but my dataframe is huge and I have to subset it many times. How can we do it more effectively in R?