clean_observations: Clean observations

Description Usage Arguments Value Examples

View source: R/clean_observations.R

Description

Replace valid observations by NAs when a given subject has more then max_na missing values.

Usage

1
clean_observations(data, id, var, max_na)

Arguments

data

A data frame, or data frame extension (e.g. a tibble).

id

The bare (unquoted) name of the column that identifies each subject.

var

The bare (unquoted) name of the column to be cleaned.

max_na

An integer indicating the maximum number of NAs per subject.

Value

The original data with the var observations matching the max_na criterion replaced by NA.

Examples

1
2
3
4
5
6
7
8
9
set.seed(10)

data <- data.frame(
  id = rep(1:5, each = 4),
  time = rep(1:4, 5),
  score = sample(c(1:5, rep(NA, 2)), 20, replace = TRUE)
)

clean_observations(data, id, score, 1)

lvmisc documentation built on April 5, 2021, 5:06 p.m.