filter_nth_entry {basecamb}R Documentation

Filter dataframe for nth entry

Description

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.#'

Usage

filter_nth_entry(data, ID_column, entry_column, n = 1, reverse_order = FALSE)

Arguments

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

Value

data.frame with <= 1 entry per subject

Author(s)

J. Peter Marquardt

Examples

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)



[Package basecamb version 1.1.5 Index]