n <- 15
dat <- data.frame(
sex=sample(c("Male","Female"), n, replace=TRUE),
age=sample(paste("Age Group",1:12), n, replace=TRUE)
)
### calculate standardized code from example hierarchy-file
# directly from a hierarchy-file
file.Sex <- paste(searchpaths()[grep("sdcTable", searchpaths())], "/etc/exampleSex.hcr", sep="")
dim.Sex <- calcDimInfos(dat, file=file.Sex, vName="sex")
print(dim.Sex)
# from a data-frame
dataAge <- read.table(paste(searchpaths()[grep("sdcTable", searchpaths())], "/etc/exampleAge.hcr", sep=""), sep=";", dec=".", colClasses="character")
dim.Age <- calcDimInfos(dat,dataframe=dataAge, vName="age")
print(dim.Age)
# duplicate levels ("BroadAgeGroup 1" is identical to Total Age"
# thus it is listed as list-element "dups" in dim.Age2
dataAge$V1[2:nrow(dataAge)] <- "@@@"
dataAge <- rbind(dataAge[1,], c("@@", "broad Age Group 1"), dataAge[2:nrow(dataAge),])
dim.Age2 <- calcDimInfos(dat,dataframe=dataAge, vName="age")
print(dim.Age2)
Run the code above in your browser using DataLab