Skip to contents

Summarise for a given time period word counts, typically calculatd with cas_count()


  date_column_name = date,
  n_column_name = n,
  pattern_column_name = pattern,
  period = NULL,
  f = mean,
  every = 1L,
  before = 0L,
  after = 0L,
  complete = FALSE,
  auto_convert = FALSE



A data frame. Must include at least a column with a date or date-time column and a column with number of occurrences for the given time.


Defaults to NULL. A string describing the time unit to be used for summarising. Possible values include "year", "quarter", "month", "day", "hour", "minute", "second", "millisecond".


Defaults to mean. Function to be applied over n for all the values in a given time period. Common alterantives would be mean or median.


[positive integer(1)]

The number of periods to group together.

For example, if the period was set to "year" with an every value of 2, then the years 1970 and 1971 would be placed in the same group.

before, after

[integer(1) / Inf]

The number of values before or after the current element to include in the sliding window. Set to Inf to select all elements before or after the current element. Negative values are allowed, which allows you to "look forward" from the current element if used as the .before value, or "look backwards" if used as .after.



Should the function be evaluated on complete windows only? If FALSE, the default, then partial computations will be allowed.


Defaults to FALSE. If FALSE, the date column is returned using the same format as the input; the minimun vale in the given group is used for reference (e.g. all values for January 2022 are summarised as 2021-01-01 it the data were originally given as dates.). If TRUE, it tries to adapt the output to the most intuitive correspondent type; for year, a numeric column with only the year number, for quarter in the format 2022.1, for month in the format 2022-01.


Defaults to date. Unquoted name of a column having either date or date-time as class.


Unquoted to n. Unquoted name of a column having number of occurrences per time unit.


A data frame with two columns: the name of the period, and the same name originally used for n.


if (FALSE) {
# this assumes dates are provided in a column called date
corpus_df %>%
    pattern = "example",
    group_by = date
  ) %>%
  cas_summarise(period = "year")