3.1 Example Data
Again we will make use of the WISC data described in Chapter 2. The following commands recreate the wide and long data we will use throughout this chapter.
filepath <- "https://quantdev.ssri.psu.edu/sites/qdev/files/wisc3raw.csv"
wisc3raw <- read.csv(file=url(filepath),header=TRUE)
var_names_sub <- c(
"id", "verb1", "verb2", "verb4", "verb6",
"perfo1", "perfo2", "perfo4", "perfo6",
"momed", "grad"
)
wiscraw <- wisc3raw[,var_names_sub]
# reshaping wide to long
wisclong <- reshape(
data = wiscraw,
varying = c("verb1", "verb2", "verb4","verb6", "perfo1","perfo2","perfo4","perfo6"),
timevar = c("grade"),
idvar = c("id"),
direction = "long",
sep = ""
)
# reorder by id and day
wisclong <- wisclong[ order(wisclong$id, wisclong$grade), ]
#reshaping long to wide
wiscwide <- reshape(
data = wisclong,
timevar = c("grade"),
idvar = c("id"),
v.names = c("verb","perfo"),
direction = "wide",
sep = ""
)
# reordering columns
wiscwide <- wiscwide[, c(
"id", "verb1", "verb2", "verb4", "verb6",
"perfo1", "perfo2", "perfo4", "perfo6",
"momed","grad"
)]