r_series {wakefield} | R Documentation |
Data Frame Series (Repeated Measures)
Description
Produce a tbl_df
data frame of repeated measures from a
wakefield variable function.
Usage
r_series(fun, j, n, ..., integer = FALSE, relate = NULL, rep.sep = "_")
Arguments
fun |
A wakefield variable function. |
j |
The number of columns to produce. |
n |
The number of rows to produce. |
integer |
logical. If |
relate |
Allows the user to specify the relationship between columns.
May be a named list of |
rep.sep |
A separator to use for repeated variable names. For example
if the |
... |
Additional arguments passed to |
Value
Returns a tbl_df
.
References
https://github.com/trinker/wakefield/issues/1/#issuecomment-96166910
See Also
Examples
r_series(grade, 5, 10)
## Custom name prefix
r_series(likert, 5, 10, name = "Question")
## Convert factors to integers
r_series(likert_7, 5, 10, integer = TRUE)
## Related variables
r_series(likert, 10, 200, relate = list(operation = "*", mean = 2, sd = 1))
r_series(likert, 10, 200, relate = "--3_1")
r_series(age, 10, 200, relate = "+5_0")
## Change sd to reduce/increase correlation
round(cor(r_series(grade, 10, 10, relate = "+1_2")), 2)
round(cor(r_series(grade, 10, 10, relate = "+1_0")), 2)
round(cor(r_series(grade, 10, 10, relate = "+1_.5")), 2)
round(cor(r_series(grade, 10, 10, relate = "+1_20")), 2)
## Plot Example 1
library(dplyr); library(ggplot2)
dat <- r_data_frame(12,
name,
r_series(likert, 10, relate = "+1_.5")
)
# Suggested use of tidyr or reshape2 package here instead
dat <- data.frame(
ID = rep(dat[[1]], ncol(dat[-1])),
stack(dat[-1])
)
dat[["Time"]] <- factor(sub("Variable_", "", dat[["ind"]]), levels = 1:10)
ggplot(dat, aes(x = Time, y = values, color = ID, group = ID)) +
geom_line(size=.8)
## Plot Example 2
dat <- r_data_frame(12,
name,
r_series(grade, 100, relate = "+1_2")
)
# Suggested use of tidyr or reshape2 package here instead
dat <- data.frame(
ID = rep(dat[[1]], ncol(dat[-1])),
ind = rep(colnames(dat[-1]), each = nrow(dat)),
values = unlist(dat[-1])
)
dat[["Time"]] <- as.numeric(sub("Grade_", "", dat[["ind"]]))
ggplot(dat, aes(x = Time, y = values, color = ID, group = ID)) +
geom_line(size=.8) + theme_bw()