Maximum CSV file

I am trying to find the overall max of one column of data across

Welcome to the site!
First order of business - read this please: Welcome to the RStudio Community!
Second order of business (and you've probably picked up on it after completing the first step) - we can help you best if you provide us with a reproducible example (a reprex).

Without a reprex, we can't help you much. What's wrong with your answer? Do you get an error? Do you get an answer, but it's an incorrect one? What is wrong, exactly?

I can't re-run your code (again, because not a reprex), but it probably should work given these conditions:

  • Your files are stored in C:/Users/12543/Documents/Stats.com folder
  • You have exactly 9 files named data20130101.csv through data20130109.csv
  • All files are identical in structure
  • All files have headers
  • All files have temperature as the second column
  • There is at least one instance of temperature over 0

I wouldn't likely use such solution, but it seems to be sound, given all conditions above are satisfied.

3 Likes
data.frame(
        time = c("0:00", "0:10", "0:20", "0:30", "0:40", "0:50", "1:00",
                 "1:10", "1:20", "1:30", "1:40"),
        temp = c(14.1, 14.2, 14.2, 13.9, 13.7, 13.5, 13.2, 13.1, 13.1, 12.8,
                 12.6),
         dew = c(11.1, 11.4, 11.4, 11.1, 11, 11, 10.9, 10.8, 11, 10.7, 10.5),
         hum = c(82L, 83L, 83L, 83L, 84L, 85L, 86L, 86L, 87L, 87L, 87L),
       speed = c(0, 0, 0, 0, 0, 0, 0, 0, 0.3, 0, 0),
        gust = c(0, 0, 0, 0, 0, 1.7, 1.7, 1.7, 1.7, 0, 0),
         dir = c(0L, 0L, 0L, 0L, 0L, 205L, 205L, 205L, 205L, 0L, 0L),
        rain = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
        baro = c(1021, 1021.3, 1021.1, 1020.9, 1020.9, 1020.8, 1020.8, 1020.8,
                 1020.6, 1020.6, 1020.5)
)

It looks like your code goes into those nine files, looks at the second column (in your example data frame, the temp variable), looks for the highest temp and checks if that local-file high-temperature is higher than your overallMaxTemp, overwriting overallMaxTemp if that file's max temp is the new highest.

I don't see anything obviously wrong in this method. (And it's not really clear what you meant by "My answer is not correct.", it might be helpful to better understand how it wasn't correct)

One easy way to check what's going wrong is store those file max temperatures into a vector and examine that.

what do you get with something like the following;

numbers <- 101:109
filenames1_9 <- paste("data20130",numbers,".csv",sep="")

overallMaxTemp <- c()
for (i in filenames){
  temps <- read.csv(i,row.names=1)
  overallMaxTemp <- c(overallMaxTemp,max(temps[,2]))
}

overallMaxTemp
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.