0

I have a dataframe, with one column as factor. I want to subtract 1 from all rows in my column, but when i try i get an error message that " - " is not meaningful for factors.

How can i do this?

henrikkh
  • 1
  • 1
  • try transforming the factor into integer or numeric and reverse it after subtracting 1. – Mohanasundaram Nov 18 '20 at 10:25
  • You can try this to convert factor to integer https://stackoverflow.com/questions/3418128/how-to-convert-a-factor-to-integer-numeric-without-loss-of-information – Ronak Shah Nov 18 '20 at 12:06

1 Answers1

1

Factors aren't numbers even though there is a numbering system under them. Thus, when you try to substract 1 from factor levels, software will error. This is a logic error, not a software error.

Did you want factors, or was your data converted to factors when you imported it? If you want numeric data, you can convert factors to numbers by using one command.

Michelle
  • 1,281
  • 2
  • 16
  • 31