Learn R Programming

wlsd (version 1.0.1)

takefirst: Subset observations for grouped data based on first occurrence of a criteria value

Description

Takes all rows of a data frame up to and including the first occurrence of a supplied criteria for grouped data.

Usage

takefirst(data, id, criteria.column, criteria)

Value

A data frame subset up to and including the first row matching criteria in cirteria.column for each level of id.

Arguments

data

A data frame with relevant columns.

id

A character string of the identification vector name defining groups in data.

criteria.column

The name as a character string of the column in data where the criteria is located.

criteria

The value of the cutoff for subsetting.

Details

Returns a data frame that takes all rows within the groups supplied by id up to and including the first occurrence of the value of criteria in criteria.column.

Examples

Run this code
takefirst(long_data, "id", criteria.column = "var1", criteria = 10.4)

Run the code above in your browser using DataLab