I have 3 csv files, I have three columns in all the three files( Maths, Physics and Chemistry) and marks of all the students. I created a loop to read all the files and saved in a dataframe as follows. In every file line numbers 1,2,4,5 need to be skipped.
files <- list.files(pattern = ".csv")
for(i in 1:length(files)){
data <- read.csv(files[i], header=F, skip=2) # by writing skip=2 I could only skip first two lines.
View(data)
mathavg[i] <- sum(as.numeric(data$math), na.rm=T)/nrow(data)
}
result <- cbind(files,mathavg)
write.csv(result,"result_mathavg.csv")
I could not able to calculate the average of math column in all the three files.
Like this I need to calculate for all the three subjects across three files. any help????