# NOT RUN {
### Get path to example source
examplePath <-
system.file("extdata", package="rock");
### Get a path to one example file
exampleFile <-
file.path(examplePath, "example-1.rock");
### Parse single example source
parsedExample <- rock::parse_source(exampleFile);
### Create a categorical attribute column
parsedExample$mergedSourceDf$age_group <-
rep(c("<18", "18-30", "31-60", ">60"), each=13);
### Expand to four logical columns
parsedExample$mergedSourceDf <-
rock::expand_attributes(
parsedExample$mergedSourceDf,
"age_group",
valueLabels =
c(
"<18" = "youngest",
"18-30" = "youngish",
"31-60" = "oldish",
">60" = "oldest"
),
valueFirst = FALSE
);
### Show result
table(parsedExample$mergedSourceDf$age_group,
parsedExample$mergedSourceDf$age_group__youngest);
table(parsedExample$mergedSourceDf$age_group,
parsedExample$mergedSourceDf$age_group__oldish);
# }
Run the code above in your browser using DataLab