Learn R Programming

AOUSDOHtools (version 1.0.4)

calc_religious_attendance: Calculate Religious Attendance Frequency

Description

This function creates an ordinal categorical variable indicating the frequency of attending religious meetings or services, based on participant responses.

Usage

calc_religious_attendance(survey_df)

Value

A data frame with two columns: `person_id` and `religious_attendance`, where `religious_attendance` indicates how often the participant attends religious meetings or services. Participants without data or who skipped the question will have NA values.

Arguments

survey_df

A data frame containing survey data with at least three columns: `person_id`, `question_concept_id`, and `answer`.

Examples

Run this code
# Create a sample survey data frame
survey_df <- data.frame(
  person_id = c(1, 2, 3, 4, 5),
  question_concept_id = rep(40192470, 5),
  answer = c("Never", "Once a week", "More than once a week", "Never", "Skip")
)

# Compute religious attendance frequency
religious_attendance_scores <- calc_religious_attendance(survey_df)
head(religious_attendance_scores)

Run the code above in your browser using DataLab