A helper function to help you format the participants data (age, sex, ...) in the participants section.

report_participants(
  data,
  age = NULL,
  sex = NULL,
  education = NULL,
  participants = NULL,
  group = NULL,
  spell_n = FALSE,
  digits = 1,
  ...
)

Arguments

data

A data frame.

age

The name of the column containing the age of the participant.

sex

The name of the column containing the sex of the participant. The classes should be one of c("Male", "M", "Female", "F"). Note that you can specify other characters here as well (e.g., "Other"), but the function will report only percentage of females, regardless of whether any category other than "Male" is present in the data.

education

The name of the column containing education information.

participants

The name of the participants' identifier column (for instance in the case of repeated measures).

group

A character vector indicating the name(s) of the column(s) used for stratified description.

spell_n

Fully spell the sample size ("Three participants" instead of "3 participants").

digits

Number of significant digits.

...

Arguments passed to or from other methods.

Value

A character vector with description of the "participants", based on the information provided in data.

Examples

library(report)
data <- data.frame(
  "Age" = c(22, 23, 54, 21, 8, 42),
  "Sex" = c("F", "F", "M", "M", "M", "F")
)

report_participants(data, age = "Age", sex = "Sex")
#> [1] "6 participants (Mean age = 28.3, SD = 16.6, range: [8, 54]; 50.0% females)"

# Years of education (relative to high school graduation)
data$Education <- c(0, 8, -3, -5, 3, 5)
report_participants(data, age = "Age", sex = "Sex", education = "Education")
#> [1] "6 participants (Mean age = 28.3, SD = 16.6, range: [8, 54]; 50.0% females; Mean education = 1.3, SD = 4.9, range: [-5, 8])"

# Education as factor
data$Education2 <- c(
  "Bachelor", "PhD", "Highschool",
  "Highschool", "Bachelor", "Bachelor"
)
report_participants(data, age = "Age", sex = "Sex", education = "Education2")
#> [1] "6 participants (Mean age = 28.3, SD = 16.6, range: [8, 54]; 50.0% females; Education: Bachelor, 50.00%; Highschool, 33.33%; PhD, 16.67%)"


# Repeated measures data
data <- data.frame(
  "Age" = c(22, 22, 54, 54, 8, 8),
  "Sex" = c("F", "F", "M", "M", "F", "F"),
  "Participant" = c("S1", "S1", "s2", "s2", "s3", "s3")
)

report_participants(data, age = "Age", sex = "Sex", participants = "Participant")
#> [1] "3 participants (Mean age = 28.0, SD = 23.6, range: [8, 54]; 66.7% females)"

# Grouped data
data <- data.frame(
  "Age" = c(22, 22, 54, 54, 8, 8, 42, 42),
  "Sex" = c("F", "F", "M", "M", "F", "F", "M", "M"),
  "Participant" = c("S1", "S1", "s2", "s2", "s3", "s3", "s4", "s4"),
  "Condition" = c("A", "A", "A", "A", "B", "B", "B", "B")
)

report_participants(data,
  age = "Age",
  sex = "Sex",
  participants = "Participant",
  group = "Condition"
)
#> [1] "For the 'Condition - A' group: 2 participants (Mean age = 38.0, SD = 22.6, range: [22, 54]; 50.0% females) and for the 'Condition - B' group: 2 participants (Mean age = 25.0, SD = 24.0, range: [8, 42]; 50.0% females)"

# Spell sample size
paste(
  report_participants(data, participants = "Participant", spell_n = TRUE),
  "were recruited in the study by means of torture and coercion."
)
#> [1] "Four participants (Mean age = 31.5, SD = 20.5, range: [8, 54]; 50.0% females) were recruited in the study by means of torture and coercion."