superspread_count: Convert single-code column(s) into "multiple choice" formats,...

View source: R/superspread_count.R

superspread_countR Documentation

Convert single-code column(s) into "multiple choice" formats, filling data with sum of counts.

Description

This function counts the number of occurrences per row in a number of categorical / single-code variables.

Usage

superspread_count(df, select_helpers = everything())

Arguments

df

Data frame to apply function to.

select_helpers

Use dplyr select helpers to apply function only to required columns. Leave blank to include everything

Value

n number of new binary / multiple-choice columns / variables, with values representing the count of row-occurrences in the original set of input categorical/single-code variables. n represents the number of unique values found in the input variables.

See Also

Other superspread functions: superspread()

Examples

## Not run: 
library(data.table)
library(dplyr)
dt <- data.table(id = 1:10000,
                 cat1 = sample(letters[1:3],10000,replace = TRUE),
                 cat2 = sample(letters[1:4],10000,replace = TRUE),
                 cat3 = sample(letters[1:5],10000,replace = TRUE))
dt <- as.data.table(dt)
superspread_count(df = dt, select_helpers = contains("cat"))

## End(Not run)


martinctc/surveytools documentation built on Nov. 21, 2024, 10:48 p.m.