creating a custom R function in SPSS for summary

Then you need to express clearly what is the data you get from SPSS.

  • There is a data frame dt that you get with dt = spssdata.GetDataFromSPSS() and that does look like your example, with columns AA and BB
  • There is a variable varcut or y that you get from SPSS? What is the class and content of y after that command: y <- spssdictionary.GetMultiResponseSet(mrsetName = "$varcut")? Does y only contain list("tot","CA","AM"), or does it also contain c("g","f") and c("a","h","s","d")?
  • If it's not part of y, how do you determine c("g","f") and c("a","h","s","d")? Where do these values come from?

And you also need to express clearly what is the result you want. If you just want to count the values in BB, then you can get that result with table(dt$BB). If you want to "cut" the values in BB and then count them, you have to explain what varcut or y looks like. If you want to use AA to count BB, you have to explain how.

You can find advice here on how to create a reproducible example.