category-row-to-column: Category to Column

category-row-to-columnR Documentation

Category to Column

Description

Category to Column

Usage

category_row_na(x, .col, ..., name = "name")

category_row_regex(x, .col, pattern, name = "name")

category_row_to_column(x, .col, ..., name = "name")

Arguments

.col

the column containing category names

...

the columns to check for NA

name

a character. Name of column

pattern

a regex pattern to match category rows

.data

a dataframe

Examples

d <- data.frame(
  x = c(NA, "A", "B", NA, "A", "B"),
  y = c("a", 1:2, "b", 1:2),
  z = c(NA, "A", "B", NA, "A", "B")
)
category_row_na(d, y, x, z)

category_row_na(d, y, x, z, name = "small")

# Cleaning a Table with two different kinds of category rows
d <- data.frame(
  x = c(NA, NA, "A", "B", NA, NA, "A", "B"),
  y = c("Table a", "Male",  1:2, "Table b", "Female",  1:2),
  z = c(NA, NA, "A", "B", NA, NA, "A", "B")
)

d |>
  category_row_regex(y, "^Table", name = "table") |>
  category_row_na(y, x, z, name = "sex")

trekonom/tblcleanr documentation built on Jan. 30, 2025, 5:28 a.m.