Skip to contents

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)

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.

Value

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

See also

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

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

Examples

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))