0
A <- data %>% 
      group_by(Agent) %>%
      summarise(across(EP:Yt.ha),mean)

The Error message is

Error: Problem with summarise() input ..2. x Input ..2 must be a vector, not a function. i Input ..2 is mean. i The error occured in group 1: Agent = "Hydro". Run rlang::last_error() to see where the error occurred.

I remember doing it by this way longback but I believe that now I must have misplaced some functions or code. Can someone tell the correct way? There are 13 variable across EP to Yt.ha

Phil
  • 7,287
  • 3
  • 36
  • 66
Avon
  • 13
  • 2

3 Answers3

1

try something like this ( you can add group by conditions):

# install if not already
install.packages("tidyverse", dependencies = T)

# load package
library(tidyverse)

# load data
data(iris)
iris

# find the mean, grouped by species
iris %>% group_by(Species) %>% summarise(across(Petal.Width:Sepal.Length, ~ mean(.x, na.rm = TRUE)))

# alternate way to find the mean for specific cols (using col index numbers)
iris %>% group_by(Species) %>% summarise(across(c(1, 3:4), ~ mean(.x, na.rm = TRUE)))
Manoj Kumar
  • 5,273
  • 1
  • 26
  • 33
1

In case you never found out. The brackets at the end were set incorrectly. Here is how it works:

A <- data %>% group_by(Agent) %>% summarise(across(EP:Yt.ha, mean))
darkhac
  • 577
  • 4
  • 22
Gigi
  • 11
  • 1
0

It would be better with reproducible code.

I would suggest something along the lines of:

data <- iris

output <- data %>%
          group_by(species) %>%
          summarise(across(petal.width:sepal.length),mean)

// or 

output <- data %>%
          group_by(species) %>%
          summarise(across(where(is.numeric), mean))
SPJ
  • 116
  • 8