| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 
 | tab=read.table("test.txt",header=TRUE)
t=1
tab1=tab[c(1:t),]
 
for (t in 1:length(tab$Tair)){
  if (tab$Tair[t]=="NAN"){
    b=tab[c(t-1,t+1),]
    v=tab$heure[t-1]
    time=c(v,v+60)
    b=cbind(b,time)
    b[,3]=as.numeric(b[,3])
    b[,4]=as.numeric(b[,4])
    reg=lm(b[,3]~b$time)
    a=as.vector(reg$coeff[2])
    b=as.vector(reg$coeff[1])
    for (i in seq(10,20,by=10)){
      tabtemp=data.frame(matrix(ncol=3,nrow=1))
      colnames(tabtemp)=c("date","heure","Tair")
      x=tab$time[2]+i
      y=a*x+b
      z=tab$date[t]
      u=tab$heure[t]+i
      tabtemp[1,]=c(z,u,y)
      tab1=rbind(tab1,tabtemp)
    }
    }else{
    if (tab$Tair[t+1]=="NAN"){
      b=tab[c(t,t+2),]
      v=tab$heure[t]
      time=c(v,v+60)
      b=cbind(b,time)
      b[,3]=as.numeric(b[,3])
      b[,4]=as.numeric(b[,4])
      reg=lm(b[,3]~b$time)
      a=as.vector(reg$coeff[2])
      b=as.vector(reg$coeff[1])
      for (i in seq(10,20,by=10)){
        tabtemp=data.frame(matrix(ncol=3,nrow=1))
        colnames(tabtemp)=c("date","heure","Tair")
        x=tab$heure[t]+i
        y=a*x+b
        z=tab$date[t]
        tabtemp[1,]=c(z,x,y)
        tab1=rbind(tab1,tabtemp)
      }
      tabtemp=data.frame(matrix(ncol=3,nrow=1))
      colnames(tabtemp)=c("date","heure","Tair")
      x=tab$heure[t]+30
      y=a*x+b
      z=tab$date[t]
      u=tab$heure[t+1]
      tabtemp[1,]=c(z,u,y)
      tab1=rbind(tab1,tabtemp)
      }else{
      b=tab[c(t,t+1),]
      v=tab$heure[t]
      time=c(v,v+30)
      b=cbind(b,time)
      b[,3]=as.numeric(b[,3])
      b[,4]=as.numeric(b[,4])
      reg=lm(b[,3]~b$time)
      a=as.vector(reg$coeff[2])
      b=as.vector(reg$coeff[1])
      for (i in seq(10,20,by=10)){
        tabtemp=data.frame(matrix(ncol=3,nrow=1))
        colnames(tabtemp)=c("date","heure","Tair")
        x=tab$heure[t]+i
        y=a*x+b
        z=tab$date[t]
        tabtemp[1,]=c(z,x,y)
        tab1=rbind(tab1,tabtemp)
      }
      tabtemp2=data.frame(matrix(ncol=3,nrow=1))
      colnames(tabtemp2)=c("date","heure","Tair")
      tabtemp2[1,]=tab[t+1,]
      tab1=rbind(tab1,tabtemp2)
    }
  }
}
}
 
tab1 | 
Partager