0

How can I stop R from converting strings to numeric while sorting a character vector of numbers? example using dplyr arrange():

nomenclature <- read_csv2(file('~/nomenclature.txt', encoding="UTF-8"))

head(nomenclature$NOMENCLATURE)
[1] "8414900090" "6108320000" "8517709000" "6104430000" "4202310090" "8479908099"

nomenclature <- nomenclature %>% arrange(NOMENCLATURE)

head(nomenclature$NOMENCLATURE)
[1] "1.52e+09"   "1.801e+09"  "1.804e+09"  "1.805e+09"  "1001190030" "1001990094"
guzu92
  • 737
  • 1
  • 12
  • 28
  • Not sure if it's exactly what you want, but you could try `nomenclature <- nomenclature %>% arrange(as.character(NOMENCLATURE))`. I haven't tested this, but it's similar to problems I've had in the past. Is there a reason I can't first convert your character strings to numeric? – Patrick Williams Mar 10 '17 at 16:56
  • 1
    Can you provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? I can't reproduce with `nomenclature<-data.frame(NOMECLATURE=c("8414900090","6108320000","8517709000","6104430000","4202310090","8479908099"));nomenclature %>% arrange(NOMECLATURE)` – MrFlick Mar 10 '17 at 16:56
  • 2
    I would guess those values are actually in there before the `arrange()` – MrFlick Mar 10 '17 at 17:14
  • @MrFlick, you're right ! the values were actually there before. My apologies. Thank you. – guzu92 Mar 10 '17 at 21:07

1 Answers1

1

Refer to MrFlick second comment: the "e+" values were actually there before the arrange()

guzu92
  • 737
  • 1
  • 12
  • 28