【发布时间】:2020-07-29 13:51:51
【问题描述】:
我想为多个 data.frame 同时计算 ICC。我所有的 data.frame 都具有相同的结构(5 列 x 83 行)。我创建了一个生成 ICC 的函数 (my_icc) 并将结果放入表中。我在这个网站上看到,当你想同时在多个 data.frame 上应用一个函数时,你需要把你的数据放到一个列表中。 (Apply a function to multiple dataframes) 但是,我的函数似乎不支持列表元素,因为我使用了函数 select。我使用选择功能,因为我想用我的 3:5 列做 ICC。如果我当时在一个 data.frame 上应用我的函数,我没有任何问题。
my_icc <- function(data) {
data %>%
select(3:4) %>% # select just the rating columns
irr::icc() %>% # calculate the ICC
unlist() %>% # turn the output list into a vector
t() %>% # transpose this vector
as_tibble() %>% # turn the vector into a table
select( # select just the columns you want
icc = value, # rename value to icc
F.value=Fvalue,
df1,
df2,
p.value,
conf.level,
lower.bound=lbound,
uper.ubound=ubound
)
}
my_icc(Radiomics.CSV[[1]])
这是我试图创建的循环以获得 ICC 同时性。我创建了一个包含 3 个 data.frame 的小列表。实际上,我想计算 1258 ICC 同时性。我所有的数据。框架,用这个函数在 R 中导入。
library(dplyr)
files <- list.files(path = "Tableau des features/", pattern="*.csv")
Radiomics.CSV <- lapply(files, function(x) {
read.csv(paste0("Tableau des features/", x))
})
my_list <- c(Radiomics.CSV[[1]], Radiomics.CSV[[2]],Radiomics.CSV[[3]])
for(i in my_list){
my_icc <- function(i) {
i %>%
select(3:4) %>% # select just the rating columns
irr::icc() %>% # calculate the ICC
unlist() %>% # turn the output list into a vector
t() %>% # transpose this vector
as_tibble() %>% # turn the vector into a table
select( # select just the columns you want
icc = value, # rename value to icc
F.value=Fvalue,
df1,
df2,
p.value,
conf.level,
lower.bound=lbound,
uper.ubound=ubound
)
}
}
my_icc(my_list)
Error: `select()` doesn't handle lists.
【问题讨论】: