简体   繁体   中英

Read the value from a cell in a csv file in R from lapply

In this code, is there a way to ask for the integer value of a specific cell in the csv file, ie row 1, col 2? I know the syntax is [, (2)] but not sure where to input that in this set of code?

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)
  
}

Changing the relevant line to the following should work:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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