Learn R Programming

petersenlab (version 1.1.0)

reverse_score: Reverse Score Variables.

Description

Reverse score variables using either the theoretical min and max, or the observed max.

Usage

reverse_score(
  data,
  variables,
  theoretical_max = NULL,
  theoretical_min = NULL,
  append_string = NULL
)

Value

Dataframe with reverse-scored variables.

Arguments

data

Data object.

variables

Names of variables to reverse score.

theoretical_max

(Optional): the theoretical maximum score.

theoretical_min

(Optional): the theoretical minimum score.

append_string

(Optional): a string to append to each variable name.

Details

Reverse scores variables using either the theoretical min and max (by subtracting the theoretical maximum from each score and adding the theoretical minimum to each score) or by subtracting each score from the maximum score for that variable.

Examples

Run this code
mydata <- data.frame(
  var1 = c(1, 2, NA, 4, 5),
  var2 = c(NA, 4, 3, 2, 1)
)

variables_to_reverse_score <- c("var1", "var2")

reverse_score(
  mydata,
  variables = variables_to_reverse_score)

reverse_score(
  mydata,
  variables = variables_to_reverse_score,
  append_string = ".R")

reverse_score(
  mydata,
  variables = variables_to_reverse_score,
  theoretical_max = 7)

reverse_score(
  mydata,
  variables = variables_to_reverse_score,
  theoretical_max = 7,
  theoretical_min = 1)

Run the code above in your browser using DataLab