0

I have the following code for analyzing some experiment data:

# Load Data
data <- read.csv("./HHT/Processed_Data/data_.csv")
data %>%
  group_by(Round) %>%
  get_summary_stats(Q1.1, type="mean_sd")

# Friedman Test
res.fried <- friedman.test(y = data$Q1.1, 
                           groups = data$Round, 
                           blocks = data$P_ID)

This works fine. I would like to write a function to quickly run the same test while only changing the y value. I wrote the following:

friedman <- function(column) {
  res <- friedman.test(y = data$column, groups = data$Round, blocks = data$P_ID)
  return(res)
}

friedman(Q1.1)

When I try to call the function, I get the following error: Error in friedman.test.default(y = data$column, groups = data$Round, blocks = data$P_ID) : 'y', 'groups' and 'blocks' must have the same length

  • within your function, change to `data[[column]]` (i.e. instead of `data$column`), and then call your function like this: `friedman("Q1.1")` – langtang Apr 03 '23 at 00:21
  • Read [`?$`](https://stat.ethz.ch/R-manual/R-devel/library/base/html/Extract.html), and see https://stackoverflow.com/q/1169456/3358272, https://stackoverflow.com/q/18222286/3358272. – r2evans Apr 03 '23 at 00:26

0 Answers0