I am a beginner to analyze several files together. I have more than 1000 files. I created the following codes:
files <- dir(".", pattern = ".csv$") # To get the names of all csv files in current directory
for (i in 1:length(files)) {
obj_name <- files %>% str_sub(end = -5)
assign(obj_name[i], read_csv(files[i]))
}
# Concatenate the imported files into a list to manipulate them at once
command <- paste0("RawList <- list(", paste(obj_name, collapse = ","), ")")
eval(parse(text = command))
rm(i, obj_name, command, list = ls(pattern = "^a20"))
YMD <- files %>% str_sub(2, 9)
#To check for i== case 1
i <- 1
df <- RawList[[i]] %>%
pivot_longer(cols = -AA, names_to = "time_sec", values_to = "BB") %>% # change into the long format
mutate(time_sec = paste(YMD[i], time_sec) %>% ymd_hms())%>%
mutate(minute = format(as.POSIXct(time_sec,format="%H:%M:%S"),"%M"))
#To run the whole dataset
Ref_com <- RawList
for (i in 1:length(RawList)) {
df1 <- RawList[[i]] %>%
pivot_longer(cols = -AA, names_to = "time_sec", values_to = "BB") %>% # change into the long format
mutate(time_sec = paste(YMD[i], time_sec) %>% ymd_hms())%>%
mutate(minute = format(as.POSIXct(time_sec,format="%H:%M:%S"),"%M"))
}
After running the whole dataset, I got only the result for the last file.
Could you please advice where I need to change the code?
Thanks in advance!