Learn R Programming

mariposa (version 0.7.3)

row_count: Count Occurrences of a Value Across Columns

Description

Counts how often a specific value appears in each row across the selected variables. Useful for data quality checks (e.g., "How many items did a respondent answer with -9?") or for creating count-based indices.

Usage

row_count(data, ..., count, na.rm = TRUE)

Value

An integer vector with one value per row — the count of how often count appears.

Arguments

data

Your survey data (a data frame or tibble).

...

The variables to check. Supports tidyselect.

count

The value to count.

na.rm

If TRUE (default), NA values are ignored. If FALSE, any row containing NA returns NA.

See Also

row_sums() for row-wise sums, row_means() for row-wise means

Other scale: efa(), pomps(), reliability(), row_means(), row_sums()

Examples

Run this code
library(dplyr)
data(survey_data)

# How many items did each respondent answer with the highest value (5)?
survey_data <- survey_data %>%
  mutate(n_top = row_count(., trust_government, trust_media,
                           trust_science, count = 5))

Run the code above in your browser using DataLab