Search code examples
rcsvminimax

Find max column value across multi csv files in R


Thank you for reading this.

I am trying to find the max value of one column from data across 2 CSV files (see file example below).

Not sure how to find the max value of a particular column (tp,)


Solution

  • Combine both the files and find max.

    df1 <- read.csv("Path to the file1", header=T, sep=",")
    df2 <- read.csv("Path to the file2", header=T, sep=",")
    data <- rbind(df1,df2)
    max(data['temp'])
    

    In case you have many files,

    setwd('Path of the folder that contains the files')   
    filenames <- list.files(full.names=TRUE)
    data <- lapply(filenames,function(i){read.csv(i)})
    df <- do.call(rbind.data.frame, data)
    max(df['temp'])