### create arbitrary wide format large-scale assessment data for two
### subjects, each with three imputations
datWide <- data.frame ( id = paste0("P",1:5), weight = abs(rnorm(5,10,1)),
country = c("USA", "BRA", "TUR", "GER", "AUS"),
sex = factor(c("female", "male", "female", "female", "male")),
matrix(data = rnorm(n=15, mean = 500, sd = 75),
nrow=5, dimnames = list(NULL, paste0("mat.pv", 1:3))),
matrix(data = rnorm(n=15, mean = 480, sd = 80),
nrow=5, dimnames = list(NULL, paste0("sci.pv", 1:3))),
stringsAsFactors=FALSE)
datLong <- wideToLong(datWide = datWide, noImp = c("id", "weight", "country", "sex"),
imp = list ( math = paste0("mat.pv", 1:3),
science = paste0("sci.pv", 1:3)))
datLong2<- wideToLong(datWide = datWide, noImp = c("id", "weight", "country", "sex"),
imp = list ( math = paste0("mat.pv", 1:3),
science = paste0("sci.pv", 1:3)),
multipleColumns = FALSE, variable.name = "varName",
value.name = "val")
Run the code above in your browser using DataLab