I have a data frame with made up chicken population number that is recorded every 3 days for a total of 10 data points each month. (This is a made-up data I'm working on to practice before working with my actual data.)
Some months are missing 1 or 2 values and I would like to make it a timeseries to eventually calculate Sen's Slope. Can someone please help me put in a placeholder so that each month has 10 rows of data each? The 4th line of code I have for the interpolation does not work.
Thank you so much in advance!
This is what I have so far:
# making a date column
df$date <- as.Date(with(df, paste(year, month, day,sep="/")), "%Y/%m/%d")
# ordering by date to run the ts()
i <- order(df$date)
# making the timeseries
allts<-ts(data$chickens[i],start=c(1,1),frequency=10)
# interpolating missing values
allts<-na_seadec(allts,algorithm="interpolation",find_frequency=F,maxgap=Inf)
The zoo package in R allows you to work with time series that have unevenly spaced time intervals, and variable frequencies (no need to interpolate data). The {mblm} package does a Thiel-Sen regression on time-series-like data. Looking at your dummy data I assume that you want to do the regression for each month. Try this: