繁体   English   中英

从 lapply 的 R 中的 csv 文件中的单元格读取值

[英]Read the value from a cell in a csv file in R from lapply

在这段代码中,有没有办法查询 csv 文件中特定单元格的 integer 值,即第 1 行,第 2 列? 我知道语法是 [, (2)] 但不确定在这组代码中的哪里输入?

wd = setwd("/Users/TK/Downloads/DataCSV")

Groups <- list.dirs(path = wd, full.names = TRUE, recursive = FALSE)
print(Groups)

Subj <- list.dirs(path = Groups, full.names = TRUE, recursive = FALSE)
print(Subj)

for(i in Subj)  {

  setwd(i)
  section_area <- list.files(path = i, pattern = "section_area", 
                             full.names = FALSE, recursive = TRUE)
  print(section_area)
  
  read_area <- lapply(section_area, read.csv)
  print(read_area)
  
}

将相关行更改为以下内容应该可以:

read_area <- lapply(section_area, function(x)read.csv(x)[1,2]) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM