Adds missing dates between earliest and latest date of a sento_measures object or two more extreme boundary dates, such that the time series are continuous date-wise. Fills in any missing date with either 0 or the most recent non-missing value.

measures_fill(
  sento_measures,
  fill = "zero",
  dateBefore = NULL,
  dateAfter = NULL
)

Arguments

sento_measures

a sento_measures object created using sento_measures.

fill

an element of c("zero", "latest"); the first assumes missing dates represent zero sentiment, the second assumes missing dates represent constant sentiment.

dateBefore

a date as "yyyy-mm-dd", to stretch the sentiment time series from up to the first date. Should be earlier than get_dates(sento_measures)[1] to take effect. The values for these dates are set to those at get_dates(sento_measures)[1]. If NULL, then ignored.

dateAfter

a date as "yyyy-mm-dd", to stretch the sentiment time series up to this date. Should be later than tail(get_dates(sento_measures), 1) to take effect. If NULL, then ignored.

Value

A modified sento_measures object.

Details

The dateBefore and dateAfter dates are converted according to the sento_measures[["by"]] frequency.

Author

Samuel Borms

Examples

# construct a sento_measures object to start with corpus <- sento_corpus(corpusdf = sentometrics::usnews) corpusSample <- quanteda::corpus_sample(corpus, size = 500) l <- sento_lexicons(sentometrics::list_lexicons[c("LM_en", "HENRY_en")], sentometrics::list_valence_shifters[["en"]]) ctr <- ctr_agg(howTime = c("equal_weight", "linear"), by = "day", lag = 7, fill = "none") sento_measures <- sento_measures(corpusSample, l, ctr) # fill measures f1 <- measures_fill(sento_measures) f2 <- measures_fill(sento_measures, fill = "latest") f3 <- measures_fill(sento_measures, fill = "zero", dateBefore = get_dates(sento_measures)[1] - 10, dateAfter = tail(get_dates(sento_measures), 1) + 15)