changes_by {quest} | R Documentation |
Change Scores from Numeric Data by Group
Description
changes_by
creates change scores (aka difference scores) from numeric
data separately for each group. It is assumed that the data is already sorted
within each group by time such that the first row for that group is earliest
in time and the last row for that group is the latest in time.
Usage
changes_by(data, vrb.nm, grp.nm, n, undefined = NA, suffix)
Arguments
data |
data.frame of data. |
vrb.nm |
character vector of colnames from |
grp.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_by
tries to circumvent
this issue by a call to round
within shifts_by
if n
is
not an integer; however that is not a complete fail safe. The problem is that
as.integer(n)
implicit in shifts_by
truncates rather than
rounds. See details of shifts_by
.
Value
data.frame of change scores by group with colnames specified by
paste0(vrb.nm, suffix)
.
See Also
change_by
changes
change
shifts_by
Examples
changes_by(data = ChickWeight, vrb.nm = c("weight","Time"), grp.nm = "Chick", n = -1L)
changes_by(data = mtcars, vrb.nm = c("disp","mpg"), grp.nm = c("vs","am"), n = 1L)
changes_by(data = as.data.frame(CO2), vrb.nm = c("conc","uptake"),
grp.nm = c("Type","Treatment"), n = 2L) # multiple grouping columns