Creates variables that represent pure within- and between-person predictors.

isolate(d = NULL, by = NULL, value = NULL, z = FALSE, which = "within")

Arguments

d

A data.frame.

by

A vector of values in d by which the data is clustered. i.e. a vector of unique participant IDs.

value

Names of columns in d to isolate. Multiple values can be given by value = c("var1", "var2", "var3")

z

Should the created values be standardized (defaults to FALSE).

which

Which component to return. "within" (default) returns within-person deviations only; "between" returns between-person means only; "both" returns both.

Value

A data.frame with additional columns for the within- and between-person variables. The new columns are labelled _cw for centered-within and _cb for centered-between.

Author

Matti Vuorre mv2521@columbia.edu

Examples

# Create within-person deviations of work stressors in BLch9.
data(BLch9)
BLch9 <- isolate(BLch9, by = "id", value = "fwkstrs")
head(BLch9)  # Now has new column for within-person work stressors.
#>    id time fwkstrs   fwkdis  freldis          x          m          y
#> 1 101    1       3 5.590119 3.034483  0.3333333  0.9828781 -1.4420726
#> 2 101    2       3 5.535224 4.620690  0.3333333  0.9279833  0.1441343
#> 3 101    3       3 3.888381 2.850575  0.3333333 -0.7188603 -1.6259807
#> 4 101    4       4 5.352242 6.398467  1.3333333  0.7450007  1.9219121
#> 5 101    5       1 4.483074 2.544061 -1.6666667 -0.1241668 -1.9324941
#> 6 101    6       2 3.339433 5.164751 -0.6666667 -1.2678081  0.6881956
#>   fwkstrs_cw
#> 1  0.3333333
#> 2  0.3333333
#> 3  0.3333333
#> 4  1.3333333
#> 5 -1.6666667
#> 6 -0.6666667