I have 7 variables (GAD_1 through GAD_7) in a data frame named emu_dirty. I need to recode the values (from 1-4 to 0-3) for all seven, but I'd rather do this in a more efficient way than listing each variable statically. Is there a way to mutate this, or loop through each of these variables?
Exploit the fact that a data frame that does not contain both numeric and character variable types can be treated as a matrix, with which can be identified to an arithmetical operator very simply.
Whenever the need to perform arithmetic operations on an all numeric object, this approach should be the first resort for its simplicity. Because of the extreme simplicity of the required operation, subtracting one from each element in the matrix, the transformation can be accomplished in the five characters of
d - 1
Transformations will not always be so simple. Suppose the rule is to add one to odd values or subtract one from even.