dimanche 31 juillet 2016

Problems with cleaning a data frame with ifelse

I am a novice at R, and trying to clean a data frame (MSdatanew) using ifelse. I want to change a variable E2_new so that wherever it was coded as "<0.057" it is now coded as "0.57". However, wherever it isn't coded as "<0.057", I wanted it to stay as originally coded.

    MSdataclean<-MSdatanew
    MSdataclean$E2_new <- ifelse(MSdataclean$E2_new=="<0.057",0.057,MSdataclean$E2_new)

The result from this is that the variable E2_new is altered even where it wasn't "<0.57"

    head(MSdatanew$E2_new)
    [1] 0.102  <0.057 2.797  11.226 5.156  10.032
    46 Levels: <0.057 >30 0.058 0.080 0.094 0.102 0.109 0.124 0.136 0.147 ... 9.711

    head(MSdataclean$E2_new)
    [1]  6.000  0.057 26.000 19.000 32.000 18.000

Any suggestions on what I'm doing wrong?

Aucun commentaire:

Enregistrer un commentaire