0

I need to convert factor or ordinal variables to scale like the SPSS feature. Is it possible to do this in R? I’ll settle for doing for it in GNU PSPP, but I’d prefer to do it in R.

I need it to match an SPSS output file. Someone made a script that they converted to scale in SPSS before outputting the file. I’m not that familiar with SPSS, and if it’s not the same as the SPSS file the analysis will be off.

Chris
  • 59
  • 5
  • Is that how SPSS does it? I need it basically to match an SPSS output file Someone made a script that they converted to scale in SPSS before outputting the file. I’m not that familiar with SPSS, so i’m sorry if it’s as simple as `as.numeric()` And if it’s not the same as the SPSS file the analysis will be off. I’ll add this to the main body of the question, because I should have iterated that. – Chris Jan 21 '19 at 22:01
  • @Chris - I didn't think SPSS gave two hoots about the variable type for a lot of analyses, and let you take means of nominal variables etc. As long as you match up the order of the factor levels to be the same as SPSS's labels, then I think it is the same thing. – thelatemail Jan 21 '19 at 22:06
  • @MrFlick, I’ll see what I can do.. I usually do but it involved some proprietary information, and wasn’t;t sure how to reproduce. I’ll try to come up with something. – Chris Jan 21 '19 at 22:06
  • @thelatemail it’s survey data and I think you’re right .. I’ll try to run the analysis without converting, but then i wonder why they took that added step – Chris Jan 21 '19 at 22:08
  • See here for a potential duplicate query - https://stackoverflow.com/questions/3418128/how-to-convert-a-factor-to-integer-numeric-without-loss-of-information – thelatemail Jan 21 '19 at 22:30
  • Awesome... my ‘R mentor' suggested: 'I think on factors, it’s better to use `as.numeric(as.character(x))` otherwise you may get inconsistent results’.. do you agree? – Chris Jan 21 '19 at 22:41

1 Answers1

2

If you want to convert a whole data frame/matrix/vector, you can use:

library(varhandle)

unfactor(data)

Chris
  • 59
  • 5
LocoGris
  • 4,432
  • 3
  • 15
  • 30