revcode: Reverse code an item or score.

View source: R/scorehelpers.R

revcodeR Documentation

Reverse code an item or score.

Description

Given an item (or score) and the minimum and maximum possible values that the item can take, this helper function reverse codes the item. For example, it turns c(0, 1, 2, 3, 4) into c(4, 3, 2, 1, 0).

Usage

revcode(x, mn, mx)

Arguments

x

A single item (or score) to reverse code.

mn

The minimum possible value that x can take.

mx

The maximum possible value that x can take.

Details

The user must supply the theoretically possible minimum and maximum values to this function (using mn and mx, respectively). Some similar functions do not require users to provide the minimum and maximum values. Instead, those functions calculate the minimum and maximum values from the data. However, in cases where not all of the possible item values are contained in the data, this would incorrectly reverse score the items. In the interest of scoring accuracy, these arguments are required for revcode.

Value

A vector the same length as x, but with values reverse coded.

Examples

item1 <- c(0, 1, 2, 3, 4)
revcode(item1, 0, 4)
item2 <- c(0, 1, 2, 3, 0)
revcode(item2, 0, 4)

PROscorerTools documentation built on Oct. 17, 2023, 9:06 a.m.