Skip to contents

Assign bins for downsampling looking data

Usage

assign_bins(
  data,
  bin_width = 3,
  time_var,
  ...,
  bin_col = ".bin",
  na_location = "tail",
  partial = FALSE
)

Arguments

data

a dataframe of looking data

bin_width

the number of items to put in each bin. Default is 3.

time_var

the name of the column representing time

...

grouping variables

bin_col

name of the column to add. Defaults to ".bin".

na_location

Where to assign NA bin numbers. "head" and "tail" respectively put the NA elements at the head and tail of the vector; "split" alternates between "tail" and "head".

partial

whether to exclude values that don't fit evenly into bins. Defaults to FALSE, so that the user is warned if a bin is incomplete.

Value

the original dataframe with an added column of bin numbers. The dataframe will be sorted by the grouping and time variables.