0

Current data frame (df)

      V1  V2  V3
 a    aa  0.11 1.11
 b    bb  3.45 2.24
 c    cc  2.23 3.45

sapply(df, class)

     V1    V2    V3 
 "factor" "factor" "factor" 

I am trying to convert V2 and V3 to numeric and this is what I tried:

  df$V2<- as.numeric(df$V2)
  df$V3<- as.numeric(df$V3)

Then it became integers like 1 2 3.

I am wondering how can I convert factors to numeric form without changing the data

Y. Lin
  • 99
  • 2
  • 7

1 Answers1

0

Try:

df$V2<- as.numeric(as.character((df$V2))
df$V3<- as.numeric(as.character((df$V3))

I know there is a different way around this, but this usually works for me.

cgage1
  • 579
  • 5
  • 15