I'm trying to learn R, and I'm having trouble accomplishing my current task at hand, and I thought someone might have some insight or suggestions to help me think through this logically.
I have a directory with multiple CSV files, each file represents a separate day of ecological measurements. Each day (file) the measurements/variables are the same, so each CSV has the same headings but contains hundreds of unique observations for each variable.
I'm trying to write a small script that:
reads the list of files in the directory, loads each file one by one while taking the mean of one specific column and then storing that mean and the associated date in a new data frame
I then want to plot the date and mean, to see how the mean value is changing over time.
Any suggestions on how to best accomplish this?
Here is my working attempt:
dir <- getwd()
file.ls <- list.files(dir, full.names = T)
count <- length(file.ls)
all.means <- data.frame()
data <- data.frame()
for(i in 1:count){
data <- read.csv(file.ls[i])
date <- data[2,1]
means <- mean(data$total_con)
all.means[i] <- cbind(all.means, date, means)
}
plot(all.means$date, all.means$means)