Reputation: 450
Time = c("7/16/2017 18:46", "7/16/2017 21:52",
"7/16/2017 23:16", "7/17/2017 4:03", "7/17/2017 5:13", "7/17/2017 5:27",
"7/17/2017 18:57", "7/17/2017 19:25", "7/17/2017 23:58", "7/18/2017 2:59",
"7/18/2017 3:27", "7/18/2017 3:59")
Flux = c(NA, NA, 4.51263406,
NA, NA, 2.291454049, NA, 4.568703192, NA, NA, 3.392520428, NA
), int = c(403.5413091, 421.5796345, NA, 410.0796897, NA, NA,
363.5271212, NA, NA, 398.9564539, NA, NA)
corr = c(422.745436,
447.6726631, NA, 420.4392183, NA, NA, 408.7056493, NA, NA, 421.8799971,
NA, NA)
dat = c(NA, NA, NA, NA, 2.316481462, NA, NA, NA, 7.11779784,
NA, NA, 2.953349661)
df$Time <- as.POSIXct(strptime(df$Timestamp, format="%m/%d/%Y %H:%M"))
which will look like...
Time Flux int corr dat
7/16/2017 18:46 NA 403.5413091 422.745436 NA
7/16/2017 21:52 NA 421.5796345 447.6726631 NA
7/16/2017 23:16 4.51263406 NA NA NA
7/17/2017 4:03 NA 410.0796897 420.4392183 NA
7/17/2017 5:13 NA NA NA 2.316481462
7/17/2017 5:27 2.291454049 NA NA NA
7/17/2017 18:57 NA 363.5271212 408.7056493 NA
7/17/2017 19:25 4.568703192 NA NA NA
7/17/2017 23:58 NA NA NA 7.11779784
7/18/2017 2:59 NA 398.9564539 421.8799971 NA
7/18/2017 3:27 3.392520428 NA NA NA
7/18/2017 3:59 NA NA NA 2.953349661
I have four columns (1 time data, 3 continuous data). I have many NA values in each column. I want to interpolate and fill the NA for all columns. Since I dont know which interpolation method I need, I would like to many interpolation methods (linear, spline etc). I tried na.approx but it didnt work.
Any help?
Upvotes: 1
Views: 81
Reputation: 7730
If you want to try and compare several interpolation methods as stated, you can use the na.interpolation()
function from the imputeTS
package.
For linear interpolation:
library("imputeTS")
na.interpolation(df, option = "linear")
For spline interpolation:
library("imputeTS")
na.interpolation(df, option = "spline")
For stineman interpolation:
library("imputeTS")
na.interpolation(df, option = "stine")
So as you can see, you just have to adapt the options parameter.
Upvotes: 1
Reputation: 450
df <- fill(df,direction = c (names(df)))
But i dont which technique it uses to fill the NA
Upvotes: 0