View source: R/quest_functions.R
changes_by | R Documentation |
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.
changes_by(data, vrb.nm, grp.nm, n, undefined = NA, suffix)
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
|
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
.
data.frame of change scores by group with colnames specified by
paste0(vrb.nm, suffix)
.
change_by
changes
change
shifts_by
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.