trimws bug? leading whitespace not removed

后端 未结 2 544
清酒与你
清酒与你 2020-12-07 01:49

Edit: Thanks to R Yoda, I was finally able to create a reproducible example to the issue I am facing:

x = rawToCha         


        
2条回答
  •  眼角桃花
    2020-12-07 02:32

    A possible solution is replace the wrongly encoded spaces with the right ones:

    trimws(rawToChar(replace(x1, x1 == as.raw(0xa0), as.raw(0x20))))
    

    which gives:

    [1] "11.132592"
    

    For conversion to numeric, just wrap above code in as.numeric.


    Used data:

    x1 <- as.raw(c(0xa0, 0x31, 0x31, 0x2e, 0x31, 0x33, 0x32, 0x35, 0x39, 0x32))
    

提交回复
热议问题