0

Very new to R so please excuse my lack of knowledge...

I am attempting to pull the max value from a column from multiple data frames. I start with a single data frame which I split using splitand I then make a list of the file names with the intention of using the list to be able to loop through each separate df to get the max from a column of each.

I am able to get the max when using:

nam2 <- paste("Max_Superheat_Value", '65002', sep = "")
assign(nam2, max(allcsvs$'65002'$SuperheatTemperature, na.rm = TRUE))

However when I try to use a for loop:

for (i in myfiles_short){
  nam2 <- paste("Max_Superheat_Value", i, sep = "")
  assign(nam2, max(allcsvs$'i'$SuperheatTemperature, na.rm = TRUE))
}

I get -Inf as a return for each of the values?

The bulk of the code for this is below, the data frames vary in length but all have the same columns due to being split from the same original data frame.

df <- split(Data, f = Data$Heatnumber)

for (Heatnumber in names (df)){
  write.csv(df[[Heatnumber]], paste0(Heatnumber, ".csv"))
}

myfiles <- list.files(pattern = '^6(.*)csv$', full.names = FALSE)
myfiles_short <- substr(myfiles,1,5)
allcsvs <- lapply(myfiles, read.csv)
names(allcsvs) <- substr(myfiles,1,5)

#nam2 <- paste("Max_Superheat_Value", '65002', sep = "")
#assign(nam2, max(allcsvs$'65002'$SuperheatTemperature, na.rm = TRUE))


for (i in myfiles_short){

  nam2 <- paste("Max_Superheat_Value", i, sep = "")
  assign(nam2, max(allcsvs$'i'$SuperheatTemperature, na.rm = TRUE))

}

0 Answers0