I am trying to create a custom R function in SPSS to get output Distinct count for dynamic Variables.
dt <- data.frame(AA =c("a","h","d","f","d","s","j","s","d","f","g","g","d","f","g","s","d","f","a","d","f"),
BB = c("ab","ac","ab","cd","da","bb","da","ac","fg","fg","bb","cd","ac","ab","da","ab","ac","an","fk","an","fk"))
# these cuts are dynamic
dt$tot<- 1
dt$CA<-ifelse(dt$AA %in% c("g","f"),1,NA)
dt$AM<-ifelse(dt$AA %in% c("a","h","s","d"), 1, NA)
val_lab(dt$tot)<-c("Total"=1)
val_lab(dt$CA)<-c("CA"=1)
val_lab(dt$AM)<-c("AM"=1)
varcut <-list("tot","CA","AM") # z can be any type of list of cuts
#dt = spssdata.GetDataFromSPSS()
#y <- spssdictionary.GetMultiResponseSet(mrsetName = "$varcut")
for (d in 1:length(dt)){
cat('\n\n#### ', names(dt)[d], '\n\n')
md<-dt[[d]]
c<-cbind('\n\n#### ', length(unique(md$BB, incomparables = FALSE)))
c<-as.data.frame(c)
names(c)<-c(" ","")
cat('\n\n')
}
#spsspivottable.Display(c, title='Number of organizations', format=formatSpec.GeneralStat,hiderowdimlabel=TRUE)
the objective is to create a custom function which can dynamically create a summary of distinct count of variables in BB column. I don't have any idea if there is any solution please help.
I am trying to create output like below.