I need to calculate the overallMin in across 5 files that I have downloaded. The filenames all have the same format:
"2013-07-citibike.csv" "2013-08-citibike.csv"
"2013-09-citibike.csv" "2013-10-citibike.csv"
"2013-11-citibike.csv" "2013-12-citibike.csv"
I need to write a for loop that reads these files, calculates the min (of one particular column) for each file and then the overall min from all files.
So far I have this
numbers <- 07:12
filenames <- paste("2013-", numbers, "-citibike", ".csv", sep="")
overallMin <- 0
for (i in filenames) {
trips <- read.csv(i)
newMin <- min(trips)
if (overallMin < newMin) {
overallMin <- newMin
}
}
overallMin
Confused with the csv part. Plus I am getting an Error: unexpected symbol in "for (i in filenames) { trips = read.csv(i) newMin"
Define the file names directly. Another thing, you need to specify the column number, or you want the minimum of all file?
or use
sprintfto get the correct file names