i have time series data. need find missing values in time series data , display user. need algorithm run fast. since output needs generated in shiny. can't keep user waiting long
# creating sample data topdays <- seq(1,6,2) topobs <- rep("adams",3) middays <- rep(seq(1:6),3) midobs <- c(rep("allen",6),rep("benton",6),rep("blackford",6)) bottomdays <- seq(1,6,2) bottomobs <- rep("brown",3) values <- runif(24, min=70, max=100) obs <- c(topobs,midobs,bottomobs) days <- c(topdays,middays,bottomdays) df <- data.frame(days,values,obs) # end creation of sample data
as see there data missing observations adams , brown @ day 2,4,6.
i want create function capture missing day , observation
the output should create data frame missing value , observation.
i have created sample of problem statement.
the real dataset big.
thanking in anticipation have looked @ this. let me know if can provide more details
we try:
library(data.table) setdt(df) setkeyv(df, c("days", "obs")) df[with(df, expand.grid(unique(days), unique(obs)))][is.na(values)]
output
days values obs 1: 2 na adams 2: 4 na adams 3: 6 na adams 4: 2 na brown 5: 4 na brown 6: 6 na brown
Comments
Post a Comment