Hello, I would like to create a data frame that takes a specific row across several columns from every .xlsx file within a folder. If the dataframe could also include the name of the file in a column too that would be great. So far I have this:
library(readxl) setwd("~/Documents/Kent/Students/FYP/2020-21/SRE_loneliness/data/OlderAdults/data") file.list <- list.files(pattern='*.xlsx') df.list <- lapply(file.list, read_excel)
Let's say you want to keep all the rows where Name == "A" and the columns Name and Value. I would use code like the following.
# Your code library(readxl) setwd("~/Documents/Kent/Students/FYP/2020-21/SRE_loneliness/data/OlderAdults/data") file.list <- list.files(pattern='*.xlsx') df.list <- lapply(file.list, read_excel) #Added code library(dplyr) library(purrr) names(df.list) <- file.list FilterFunc <- function(DF) filter(DF, Name == "A") |> select(Name, Value) map(df.list, FilterFunc) |> bind_rows(.id = "File")