Convert character accurately

1

Considering that the content of a certain variable is "001" class character .

I need to convert such a character to numeric. If I do as.numeric() , it returns me 1 .

I want you to return me exactly 001, is it possible?

Thank you.

    
asked by anonymous 11.06.2014 / 17:16

1 answer

4

The problem is in == and not in class. == works only for one value. To compare with more than one value, it must be %in% . In your case:

desp2[desp2$codigo_novo %in% c('1049', '1001'),]

In the same way subset:

subset(desp2, codigo_novo %in% c('1049', '1001'))

Using == , it would take two comparisons:

desp2$codigo_novo == '1049' | desp2$codigo_novo == '1001'
    
13.06.2014 / 00:26