samedi 2 novembre 2019

Issue with making a loop that creates df with yearly data

I have a df which contains daily precipitation data for 40 years from 49 different grindpoints (v_i_p files) and i want to make a loop that creates a new one (with names "r95_"i) which contains how many times per year we had precipitation over 0.00091 for each grindpoint . I made a loop using the yearly endpoints and some if's however instead of creating a df with 40 different values (one for each year) it just adds them.

(In the example code i used the endpoints for just the first 2 years)

for (i in 1:49) {
  name<-paste0("r95_",i,sep="")   
  name2<-paste0("v_",i,"_p",sep="")
    for (j in 1:365) {
    if (get(name2)[j]>0.00091){
      name[1]<-(get(name)+1)
    }
  }  
  for (k in 366:731) {
    if (get(name2)[k]>0.00091){
      name[2]<-(get(name)+1)
    }
  }
}

Thank you in advance for your help, i really appreciate it

Aucun commentaire:

Enregistrer un commentaire