This seems to me a very simple question but I don't manage to come up with an efficient idea.
I have a data frame in R so composed:
- column
position
generated asseq(from = 1, to = nrow(df), by = 1)
- column
value
, with some values associated with the position
I want to group the dataframe each k rows (k being an integer input) and then calculate the mean of each group.
The dplyr function group_by
does not allow me to group for a specific integer number of rows.
How can I do that? Is there a way to avoid creating the column position at all?