Hi,
I have below data
dat2 = c("-24.437285333333300", "4.850695000000000",
"-1.918495666666670",
"2.641818000000000", "6.777527666666670",
"3.208084000000000",
"4.193287666666670", "0.378257666666667",
"4.658955000000000",
"?-9.881474000000000")
Now when I try to convert this data to numeric, I got NA as below
> as.numeric(dat2)
[1] -24.4372853 4.8506950 -1.9184957 2.6418180 6.7775277 3.2080840
[7] 4.1932877 0.3782577 4.6589550 NA
Could you please help to understand why I get NA for the last value?
> sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS 15.3.1
Matrix products: default
BLAS:
/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
LAPACK:
/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;
LAPACK version 3.12.0
locale:
[1] C/UTF-8/C/C/C/C
time zone: Asia
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.4.0
? Mon, 3 Mar 2025 12:08:43 +0530 Christofer Bogaso <bogaso.christofer at gmail.com> ?????:> dat2 = c("-24.437285333333300", "4.850695000000000", > "-1.918495666666670", > > "2.641818000000000", "6.777527666666670", "3.208084000000000", > > "4.193287666666670", "0.378257666666667", "4.658955000000000", > > "?-9.881474000000000") > > Now when I try to convert this data to numeric, I got NA as below > > > as.numeric(dat2) > > [1] -24.4372853 4.8506950 -1.9184957 2.6418180 6.7775277 > 3.2080840 > > [7] 4.1932877 0.3782577 4.6589550 NAThere's an invisible Unicode character in there, U+FEFF ZERO WIDTH NO-BREAK SPACE:> dat2 |> tail(1) |> tools::showNonASCII()1: <ef><bb><bf>-9.881474000000000 Try as.numeric(gsub('\ufeff', '', dat2)). -- Best regards, Ivan