I am working on a function that extract the contents of several CSV files and put in one data frame and then get the mean of a specific component of that data frame specified by the user
> airpollut <- function(pathway, pollutent, id = 1:322){
+   airpollutionfiles <- list.files(path = pathway, full.names = TRUE, pattern = ".csv")
+   totalvalues <- list()
+   for(i in id){
+    filereading <- read.csv(airpollutionfiles[i])
+    totalvalues[[i]] <- filereading
+   }
+   finaldata1 <- data.frame(rbind(totalvalues))
+   mean(finaldata1[[pollutent]])
+   }
but when I run the function I will get the error message:
> airpollut("finaldata", "sulfate")
[1] NA
Warning message:
In mean.default(finaldata1[[pollutent]]) :
  argument is not numeric or logical: returning NA
so I tried to check out the output of that dataframe binding and I removed the mean function from the function I am creating and put head() instead:
airpollut <- function(pathway, pollutent, id = 1:322){
  airpollutionfiles <- list.files(path = pathway, full.names = TRUE, pattern = ".csv")
  totalvalues <- list()
  for(i in id){
   filereading <- read.csv(airpollutionfiles[i])
   totalvalues[[i]] <- filereading
  }
  finaldata1 <- data.frame(rbind(totalvalues))
  head(finaldata1)
}
the output is just the data stacked next to each other like a vector and my computer crushes. can you please tell me how to combine the rows from all the files? without using functions that are not in r base.
 
    