filter_recode: Filtering and recoding data

View source: R/data_process.R

filter_recodeR Documentation

Filtering and recoding data

Description

Filters data based on named vectors or list of them. Filtered series can be recoded at the same time, and also columns are returned as factor with levels in order of filtering information.

Usage

filter_recode(dat, ..., query = NULL, droplevels = TRUE, check = FALSE)

Arguments

dat

A data.frame to filter and recode.

...

A (named) vector with a name.

query

A same as ... as a list. Overrides dots.

droplevels

A locigal to droplevels of factors. Default TRUE.

check

Whether to check missing levels.

Details

Gives message for missing filtering levels.

Examples

data.frame(tieto = c("taso kaksi", "taso kaksi", "taso yksi"), tieto2 = c("a", "b", "c")) |>
  filter_recode(
  tieto = c("Yksi" = "taso yksi",
            "Kaksi" = "taso kaksi"),
  tieto2 = c("b", "c")) |>
  str()

# Puuttuvan tiedon tarkistaminen
data.frame(tieto = c("taso kaksi", "taso kaksi", "taso yksi"), tieto2 = c("a", "b", "c")) |>
  filter_recode(
  tieto = c("Yksi" = "taso yksi",
            "Kaksi" = "taso kaksi",
            "Kolme" = "taso kolme"),
  tieto2 = c("a", "b", "c", "d"), check = TRUE) |>
  str()

data.frame(tieto = c("taso kaksi", "taso kaksi", "taso yksi"), tieto2 = c("a", "b", "c")) |>
  filter_recode(
  tieto = c("Yksi" = "taso"),
  tieto2 = c("a", "b", "c"), check = TRUE) |>
  str()

pttry/pttdatahaku documentation built on Jan. 25, 2025, 10:37 a.m.