set.seed(234234)
N <- 200
mydf <- data.frame(x5 = rnorm(N),
x4 = rpois(N, lambda = 3),
x3 = ordered(sample(c("lo", "med", "hi"),
size = N, replace=TRUE),
levels = c("med", "lo", "hi")),
x2 = letters[sample(c(1:4,6), N, replace = TRUE)],
x1 = factor(sample(c("cindy", "bobby", "marcia",
"greg", "peter"), N,
replace = TRUE)),
x7 = ordered(letters[sample(c(1:4,6), N, replace = TRUE)]),
x6 = sample(c(1:5), N, replace = TRUE),
stringsAsFactors = FALSE)
mydf$x4[sample(1:N, 10)] <- 999
mydf$x5[sample(1:N, 10)] <- -999
## Should be same as content of
## write.csv(mydf, file = "../inst/extdata/mydf.csv", row.names = FALSE)
mydf.templ <- keyTemplate(mydf, file = "mydf.templ.csv")
mydf.templ_long <- keyTemplate(mydf, long = TRUE, file = "mydf.templlong.csv")
## write.csv(mydf.templ, file = "../inst/extdata/mydf.templ.csv", row.names = FALSE)
## write.csv(mydf.templ_long, file = "../inst/extdata/mydf.templ_long.csv", row.names = FALSE)
## smartSave(mydf.templ, file = "mydf.templ.xlsx", outdir = ".")
## smartSave(mydf.templ_long, file = "mydf.templ_long.xlsx", outdir = ".")
## Try with the national longitudinal study data
data(natlongsurv)
natlong.templ <- keyTemplate(natlongsurv, file = "natlongsurv.templ.csv",
max.levels = 15, sort = TRUE)
natlong.templlong <- keyTemplate(natlongsurv, long = TRUE,
file = "natlongsurv.templ_long.csv", sort = TRUE)
if (require(openxlsx)){
openxlsx::write.xlsx(natlong.templ, file = "natlongsurv.templ.xlsx")
openxlsx::write.xlsx(natlong.templlong, file = "natlongsurv.templ_long.xlsx")
}
Run the code above in your browser using DataLab