socdem_table: Socio-demographics table

View source: R/socdem_table.r

socdem_tableR Documentation

Socio-demographics table

Description

This function takes socio-demographic variables and transforms them into a printable table. A numeric variable representing age (in years) will be summarized as mean and standard deviation. Gender and education will be returned as frequency tables.

Usage

socdem_table(age, gender, edu, gender_labels = NULL, edu_labels = NULL,
  frequency = TRUE, percent = TRUE)

Arguments

age

A numeric variable representing the age of the participants.

gender

A numeric or factor variable representing the gender of the participants.

edu

A numeric or factor variable representing the educational level of the participants.

gender_labels

If gender is of class "numeric", you can provide a vector with factor labels.

edu_labels

If edu is of class "numeric", you can provide a vector with factor labels.

frequency

Logical value indicating whether frequencies should be returned.

percent

Logical value indicating whether percentages should be returned.

Value

The table summarizing the socio-demographic characteristics of a data frame.

Examples

# Creating variables
age <- c(20, 21, 25, 35, 19, 20)
gender <- c(rep("female", 3), rep("male", 3))
edu <- c(rep("highschool", 2), rep("middleschool", 4))

# Summarizing
(table_1 <- socdem_table(age, gender, edu))

# Rmarkdown table
papaja::apa_table(
  table_1,
  caption = "Socio-Demographics",
  stub_indents = list("Gender" = c(2,3),
                      "Education" = c(4,5))
)

masurp/pmmisc documentation built on May 3, 2024, 7:13 p.m.