changes {quest} | R Documentation |
Change Scores from Numeric Data
Description
changes
creates change scores (aka difference scores) from numeric
data. It is assumed that the data is already sorted by time such that the
first row is earliest in time and the last row is the latest in time.
changes
is a multivariate version of change
that operates
on multiple variabes rather than just one.
Usage
changes(data, vrb.nm, n, undefined = NA, suffix)
Arguments
data |
data.frame of data. |
vrb.nm |
character vector of colnames from |
n |
integer vector with length 1. Specifies how the change score is
calculated. If |
undefined |
atomic vector with length 1 (probably makes sense to be the
same typeof as |
suffix |
character vector of length 1 specifying the string to append to
the end of the colnames of the return object. The default depends on the
|
Details
It is recommended to use L
when specifying n
to prevent
problems with floating point numbers. shifts
tries to circumvent this
issue by a call to round
within shifts
if n
is not an
integer; however that is not a complete fail safe. The problem is that
as.integer(n)
implicit in shifts
truncates rather than rounds.
See details of shifts
.
Value
data.frame of change scores with colnames specified by
paste0(vrb.nm, suffix)
.
See Also
change
changes_by
change_by
shifts
Examples
changes(attitude, vrb.nm = names(attitude),
n = -1L) # use L to prevent problems with floating point numbers
changes(attitude, vrb.nm = names(attitude),
n = -2L) # can specify any integer up to the length of `x`
changes(attitude, vrb.nm = names(attitude),
n = +1L) # can specify negative or positive integers
changes(attitude, vrb.nm = names(attitude),
n = +2L, undefined = -999) # user-specified indefined value
changes(attitude, vrb.nm = names(attitude),
n = -2L, undefined = -999) # user-specified indefined value
## Not run:
changes(str2str::d2d(InsectSprays), names(InsectSprays),
n = 3L) # character vector returns an error
## End(Not run)