Code

A friend sends me a .zip with folders for different rats containing .csvs with their values for something and he wants the values in each .csv for each different rat, day of the experiment, method, slice, and region of interest. Unfortunately he also wants this done in R. Code follows.

library(data.table)
files <- list.files(pattern = ".csv", recursive = T)
temp <- lapply(files, fread, sep = ",")
data <- rbindlist(temp)
v1 <- substr(start = 4, stop = 4, files)
v2 <- substr(start = 8, stop = 9, files)
v3 <- substr(start = 12, stop = 13, files)
v4 <- substr(start = 38, stop = 39, files)
v5 <- substr(start = 41, stop = 44, files)
data <- do.call(rbind, Map(cbind, temp, Rat = v1, Day = v2, Method = v3, Slice = v4, Region = v5))
data[, 3:8]