fill.md <-function(x,indices) { # indices: Indices der fehlenden Positionen # x : Ergebnisvektor, bei dem fehlende Werte eliminiert sind # # Aufruf-Beispiel: # indices <- which(is.na(mpg)|is.na(hp)|is.na(wt)) # res <- fillmd1(lm$residuals, indices]) # n<-length(indices) ii<-1 # nächste Position in indices iy<-1 # nächste Position in y ix<-1 # nächste Position in x y<-rep(NA,length(x)+n) # Übernehme x in y zwischen 2 Lückenpositionen while (ii<=n) { ia<-ix ie<-indices[ii]-ii if (ia<=ie) { for (j in ia:ie) { y[iy]<-x[ix] ; ix<-ix+1 ; iy<-iy+1 } } y[iy]<-NA iy<-iy+1 ii<-ii+1 } # Übernehme x in y hinter der letzten Lückenposition if (iy<(length(x)+n)) { ia<-iy ie<-(length(x)+n) for (j in ia:ie) { y[iy]<-x[ix] ; ix<-ix+1 ; iy<-iy+1 } } y }