Learn R Programming

AOUSDOHtools (version 1.0.4)

calc_num_moves: Calculate Number of Moves in the Past Year

Description

This function creates a numeric variable representing the number of times a participant has moved in the past 12 months.

Usage

calc_num_moves(survey_df)

Value

A data frame with two columns: `person_id` and `num_moves`, where `num_moves` represents the number of moves in the past year for each participant. 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(40192441, 5),
  answer = c("0", "1", "2", "3", "Skip")
)

# Compute number of moves in the past year
num_moves_scores <- calc_num_moves(survey_df)
head(num_moves_scores)

Run the code above in your browser using DataLab