I am new to coding and am having trouble with this problem. Here is a simplified version of my dataset:
Plot x1 x2 x3
1 1 1 2 3
2 1 3 4 5
3 2 4 5 6
4 2 6 7 8
5 3 7 8 9
6 3 9 10 11
I want to make a new dataset where the data is grouped by 'Plot' and each column has the average value for that column's plot. For this example, I would want to take the above dataset and create a dataset like the following:
Plot x1 x2 x3
1 1 2 3 4
2 2 5 6 7
3 3 8 9 10
I usually use code that looks like this when I am averaging:
require(dplyr)
dataAvg <- data %>%
dplyr::group_by(Plot) %>%
dplyr::summarise(meanx1=mean(x1))
dataAvg
However, the issue here is that I would need to specify each column that gets averaged. My actual dataset has a large number of columns to be averaged, so this does not work.
Any help would be hugely appreciated. I realize that this is likely a somewhat simple question, but I was not able to find an answer by using the search function on Stack Overflow. Please let me know if I can provide any other information for further clarity. Thanks so much for your time.