首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >同时计算多个数据的ICC

同时计算多个数据的ICC
EN

Stack Overflow用户
提问于 2020-07-29 13:51:51
回答 1查看 162关注 0票数 0

我想同时计算多个data.frame的国际商会。我的所有data.frame都有相同的结构(5列和83行)。我创建了一个函数(my_icc),它生成ICC并将结果放入一个表中。我在这个网站上看到,当你想同时在多个data.frame上应用一个函数时,你需要把你的数据放到一个列表中。(将函数应用于多个数据文件)但是,我的函数似乎不支持list元素,因为我使用函数select。我使用select函数,因为我想用我的3:5列来做ICC。如果我当时在一个data.frame上应用我的函数,我没有任何问题。

代码语言:javascript
复制
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结果

这是我试图创建的循环,以获得ICC的同时性。我用3 data.frame创建了一个小列表。实际上,我想同时计算1258个ICC。我所有的数据。具有此功能的框架在R中被导入。

代码语言:javascript
复制
library(dplyr)

files <- list.files(path = "Tableau des features/", pattern="*.csv")
 Radiomics.CSV <- lapply(files, function(x) {
    read.csv(paste0("Tableau des features/", x))
})
代码语言:javascript
复制
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)
代码语言:javascript
复制
Error: `select()` doesn't handle lists.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-29 18:39:16

在这种情况下,你不需要名单。因为您的文件名是数字,所以只需要在for循环中指定表示名称的数字间隔。

代码语言:javascript
复制
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个分隔的文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63155186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档