提问人:kannally 提问时间:4/3/2023 更新时间:4/3/2023 访问量:21
将列名传递给 r [duplicate] 中的函数时出错
Error in passing column name to function in r [duplicate]
问:
我有以下代码用于分析一些实验数据:
# 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)
这工作正常。我想编写一个函数来快速运行相同的测试,同时只更改 y 值。我写了以下内容:
friedman <- function(column) {
res <- friedman.test(y = data$column, groups = data$Round, blocks = data$P_ID)
return(res)
}
friedman(Q1.1)
当我尝试调用该函数时,出现以下错误:Error in friedman.test.default(y = data$column, groups = data$Round, blocks = data$P_ID) : 'y', 'groups' and 'blocks' must have the same length
答: 暂无答案
评论
data[[column]]
data$column
friedman("Q1.1")
?$
,并查看 stackoverflow.com/q/1169456/3358272, stackoverflow.com/q/18222286/3358272。