I want to loop through some dataframes to find the max value in their respective first columns.
- All dataframes have the same column names. (Say, 'col1' 'col2')
- All dataframes have similar names (Say, 'file1' 'file2' 'file3')
- All columns are numerical
Below is a dummy code.
The max() function returns a value of type String instead of Numeric. In other words, it returns file1$col1, instead of the maximum number that corresponds to file1$col1.
allTheMax <- matrix(nrow=3, ncol=1) #DF to put my max values in.
for(i in 1:3){
tempName <- paste("file",i,"$col1", sep="")
allTheMax[i,1] <- max(tempName)
}
Instead of getting a numeric value as the max, R returns the string I concatenated using the 'paste' function.