Search code examples
rcsvcelllapply

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


Solution

  • Changing the relevant line to the following should work:

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