View source: R/filter_nth_entry.R
filter_nth_entry | R Documentation |
Filter a dataframe for the nth entry of each subject in it. A typical use cases would be to filter a dataset for the first or last measurement of a subject.#'
filter_nth_entry(data, ID_column, entry_column, n = 1, reverse_order = FALSE)
data |
the data.frame to filter |
ID_column |
character column identifying subjects |
entry_column |
character column identifying order of entries. That column can by of types Date, numeric, or any other type suitable for order() |
n |
integer number of entry to keep after ordering |
reverse_order |
logical when TRUE sorts entries last to first before filtering |
data.frame with <= 1 entry per subject
J. Peter Marquardt
data <- data.frame(list(ID = rep(1:5, 3), encounter = rep(1:3, each=5), value = rep(4:6, each=5)))
filter_nth_entry(data, 'ID', 'encounter')
filter_nth_entry(data, 'ID', 'encounter', n = 2)
filter_nth_entry(data, 'ID', 'encounter', reverse_order = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.