# loading micro data
sp <- searchpaths()
fn <- paste(sp[grep("sdcTable", sp)], "/data/microData1.RData", sep="")
microData <- get(load(fn))
# having a look at the data structure
str(microData)
# we can observe that we have a micro data set consisting of two spanning
# variables ('region' and 'gender') and one numeric variable ('val')
# specify structure of hierarchical variable 'region'
# levels 'A' to 'D' sum up to a Total
dim.region <- data.frame(
levels=c('@','@@','@@','@@','@@'),
codes=c('Total', 'A','B','C','D'),
stringsAsFactors=FALSE)
# specify structure of hierarchical variable 'gender'
# levels 'male' and 'female' sum up to a Total
dim.gender <- data.frame(
levels=c('@','@@','@@'),
codes=c('Total', 'male','female'),
stringsAsFactors=FALSE)
# create a list with each element being a data-frame containing information
# on a dimensional variables
dimList <- list(dim.region, dim.gender)
# name the list:
# - first list-element: corresponds to variable 'region'
# - second list-element: corresponds to variable 'gender'
names(dimList) <- c('region', 'gender')
# specify the indices where dimensional variables are located
# within the input data
# - variable 'region': first column
# - variable 'gender': second column
dimVarInd <- c(1,2)
# third column containts a numeric variable
numVarInd <- 3
# no variables holding counts, numeric values, weights or sampling
# weights are available in the input data
freqVarInd <- weightInd <- sampWeightInd <- NULL
# creating an object of class \code{\link{sdcProblem-class}}
problem <- makeProblem(
data=microData,
dimList=dimList,
dimVarInd=dimVarInd,
freqVarInd=freqVarInd,
numVarInd=numVarInd,
weightInd=weightInd,
sampWeightInd=sampWeightInd)
# what do we have?
print(class(problem))
Run the code above in your browser using DataLab