0

I want to implement KTSP classifier in R, and for that it says that phenoGroup must be a factor with exactly 2 levels. Now, my labels for training_data are in the form of dataframe having values 0 and 1 (shown in attached image). I want to convert them into factor with 2 levels '0' and '1'. Can someone please tell me how to do it?

enter image description here

camille
  • 16,432
  • 18
  • 38
  • 60
Aadi
  • 41
  • 6
  • 1
    Maybe you need `training_data$phenoGroup <- as.factor(training_data$phenoGroup)`? – nniloc Sep 22 '20 at 18:26
  • 1
    See the guidance on making a [reproducible example](https://stackoverflow.com/q/5963269/5325862): a picture of data isn't particularly useful, since we can't copy & paste it. That's not super important in this case since the data is really simple, but in general. Is there any reason why something straightforward like `as.factor` doesn't work? What have you tried? – camille Sep 22 '20 at 18:32
  • Thank you, as.factor() helped to resolve my issue – Aadi Sep 22 '20 at 20:35

1 Answers1

0

I would do this:

df$phenoGroup <- as.factor(df$phenoGroup)

or:

df[, 'phenoGroup'] <- as.factor(df[, 'phenoGroup'])

both would do the job

Ivn Ant
  • 135
  • 8