vendredi 23 juin 2017

ifelse with saving objects doesn't work

I will create a loop which creates a model. The model with the highest value should be use later,

d <- data.frame()

for(i in 1:100){

  model <- lm(...)

  d <- rbind(d,model_result)

  # here the results should be saved

  # if the model_result is higher than the highest before (in data frame "d") it 
  should be saved, so that i can use it later.


  ifelse(model_result > max(d$V1), saveRDS(model,file = "mymodel.rds"), "")
}

model <- readRDS("mymodel.rds")

the saving works, but not only by the highest value will be saved rather then EVERY Value, so the model which is savest is always the latest in loop and not the highest.

I still tried other if-else functions but no one works.

Aucun commentaire:

Enregistrer un commentaire