revcode {PROscorerTools} | R 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 |
mx |
The maximum possible value that |
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)