Closed huda888 closed 4 years ago
hi @huda888 please provide a reproducible example demonstrating what you actually did and what you want to achieve. thx.
hi @bernhard-da thanks for you, really I was apply Recoding and K-anonymity on some variables on my dataset by the code below. I want to view the result of Recoding and K-anonymity on the dataset from Rstudio, what should be add to see the resulted. Note that when executing this code, it does not give any errors, but the modified database does not open for me
the code without comments (Because the comments appeared as a side title):
library(sdcMicro)
obj <- NULL inputdata <- readMicrodata(path="C:/Users/hudao/AppData/Local/Temp/RtmpktJC11/0ff58260a06f4a69c296ee77/bank.csv", type="csv", convertCharToFac=FALSE, drop_all_missings=TRUE, header=TRUE, sep=";") inputdataB <- obj$inputdata
comment: Set up sdcMicro object
sdcObj <- createSdcObj(dat=inputdata, keyVars=c("education"), numVars=c("age"), weightVar=NULL, hhId=NULL, strataVar=NULL, pramVars=NULL, excludeVars=NULL, seed=0, randomizeRecords=FALSE, alpha=c(1))
comment: Store name of uploaded file
opts <- get.sdcMicroObj(sdcObj, type="options") opts$filename <- "bank.csv" sdcObj <- set.sdcMicroObj(sdcObj, type="options", input=list(opts))
comment: Recode variable
sdcObj <- groupAndRename(obj=sdcObj, var="education", before=c("primary","secondary"), after=c("primary_secondary"), addNA=FALSE) comment:Recode variable sdcObj <- groupAndRename(obj=sdcObj, var="education", before=c("tertiary","unknown"), after=c("tertiary_unknown"), addNA=FALSE) comment: Local suppression to obtain k-anonymity sdcObj <- kAnon(sdcObj, importance=c(1), combs=NULL, k=c(5))
@huda888 thx for providing the examples.
after you run the script, you have sdcObj
which contains all the original as well as modified variables. in order to extract information from this object,, you may want to use get.sdcMicroObj()
(examples provided via ?get.sdcMicroObj
). For example, results on k-anonymity are storged in slot manipKeyVars
of this object that you can access via get.sdcMicroObj(sdcObj, "manipKeyVars")
.
To write the safe-file, you may want to use function writeSafeFile()
.
I am closing this as everything seems to work as expected.
@bernhard-da thanks a lot
If I modify in the R script after executed some steps in sdcApp, what are the commands shuld be added to shw the results on modified dataset. I am new user for R.