我想同时计算多个data.frame的国际商会。我的所有data.frame都有相同的结构(5列和83行)。我创建了一个函数(my_icc),它生成ICC并将结果放入一个表中。我在这个网站上看到,当你想同时在多个data.frame上应用一个函数时,你需要把你的数据放到一个列表中。(将函数应用于多个数据文件)但是,我的函数似乎不支持list元素,因为我使用函数select。我使用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.发布于 2020-07-29 18:39:16
在这种情况下,你不需要名单。因为您的文件名是数字,所以只需要在for循环中指定表示名称的数字间隔。
my_icc <- function(i) {
i %>%
select(3:5) %>% # 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, # un peu enlever les paramètres que nous ne voulons pas
df1,
df2,
p.value,
conf.level,
lower.bound=lbound,
uper.ubound=ubound
)
}
for (x in 1:1258) {
write.csv(data.frame(my_icc(Data[[x]])), paste0('/Users/T/Desktop/Rstudio/ICCs/',x,'.csv'), row.names = T)
}此循环将返回1258个分隔的文件。
https://stackoverflow.com/questions/63155186
复制相似问题