How Do I?

This page contains common questions & some answers! More coming soon!

How Do I? 💭

Change the parts in CAPS to match your data!

How do I create a composite (mean) score?


DATA <- DATA %>% 
    dplyr::rowwise() %>% 
    dplyr::mutate(
    NEW_COLUMN_NAME = mean(c(VARIABLE1, VARIABLE2, VARIABLE3)))

Any rows with missing data will have NA in the new column

How do I create a composite (mean) score when I have missing data?


DATA <- DATA %>% 
    dplyr::rowwise() %>% 
    dplyr::mutate(
    NEW_COLUMN_NAME = mean(c(VARIABLE1, VARIABLE2, VARIABLE3), na.rm = TRUE))

By including the na.rm argument, we can calculate the mean of our variables, even where there is missing data in any of them

How do I create a composite (mean) score with a certain amount of missing data?
VARIABLE_MEAN <- DATA %>% 
      dplyr::select(VARIABLE1, VARIABLE2, VARIABLE3) %>% 
      sjstats::mean_n(., 2) %>% 
      tibble::as_tibble_col(., column_name = "VARIABLE_MEAN")

DATA <- cbind(DATA, VARIABLE_MEAN)

The first part creates a mean of the variables we have selected, only where there are at least 2 responses (you can use any number here in the mean_n() function), and produces a tibble called varible_mean which contains those values. The second part binds that new column to our existing data


Submit your ‘How do I?’ here