Browse Source

Fill-forward algorithm

Petra Lamborn 5 years ago
parent
commit
449123773a
1 changed files with 1 additions and 11 deletions
  1. 1
    11
      R/weathmod.R

+ 1
- 11
R/weathmod.R View File

@@ -25,17 +25,7 @@ str(wantdf)
25 25
 # If all values are NA will hang, but this shouldn't happen either
26 26
 fulltemp <- left_join(wantdf, tempdf, by = c("temp_timestamp", "temp_date"))
27 27
 str(fulltemp)
28
-for (coln in names(fulltemp)[3:7]) {
29
-    tc <- fulltemp[[coln]]
30
-    if (is.na(tc[1])) {
31
-        print("First value of column is NA; Imputing from median")
32
-        tc[1] <- median(tc, na.rm = TRUE)
33
-    }
34
-    while (sum(is.na(tc)) != 0){
35
-        tc <- ifelse(is.na(tc), lag(tc, 1), tc)
36
-    }
37
-    fulltemp[[coln]] <- tc
38
-}
28
+fulltemp <- fill(fulltemp, tmax_c:rhmean)
39 29
 sum(is.na(fulltemp$tmin_c))
40 30
 fulltemp$runmin <- runmin(fulltemp$tmin_c, 48, endrule = "min", align = "right")
41 31
 fulltemp$runmax <- runmax(fulltemp$tmax_c, 48, endrule = "max", align = "right")