Используя R
, вы можете сначала найти все CSV, содержащиеся в одной папке, а затем выполнить sapply
над этим вектором (используя пакет dplyr
для выполнения требуемых операций). Наконец, найдите файлы результатов в той же папке, которая указана в list.files
.
library(dplyr)
#Find all the csv files in the indicated path
#Change the path location to the folder where you have your csv files
file_locs<-list.files(path="C:/Folder with csvs",
pattern = ".csv",
full.names = T)
sapply(file_locs, function(x){
#Read csv, skipping first line if it contains the A, b, c entries
#as headers, if not you can remove the "skip = 1"
df<-read.csv(x, skip = 1)
#Use dplyr to get the Value sum, grouped by Name
resuls<-df %>%
group_by(Name) %>%
summarize(sumVal = sum(Value))
#Get the csv original name, i.e., without the .csv part
file_name<-strsplit(x,".csv")[[1]][1]
#Write the results using the original file name and adding: _resul
write.csv(resuls, paste0(file_name,"_resul.csv"),row.names = F)
})