我不确定这是R/R Studio本身的问题,还是与我的计算机相关的Java问题。我在通过SQL从数据库导入的数据中显示注册商标符号(带圆圈的R)时遇到了问题。但是,当我通过Excel下载此数据时(其中正确读取了注册商标符号),将商标符号从Excel文件读取到R/R Studio中没有问题。根据我的阅读,这个unicode字符在拉丁文-1附录中,所以我不知道这是不是我的R工作室设置的问题。
这是我的会话信息。
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] DBI_1.1.0 odbc_1.2.2 feasts_0.1.6 fable_0.2.1 fabletools_0.2.0 tsibble_0.9.1
[7] lubridate_1.7.4 writexl_1.2 forcats_0.4.0 stringr_1.4.0 dplyr_1.0.0 purrr_0.3.3
[13] readr_1.3.1 tidyr_1.1.0 tibble_3.0.3 ggplot2_3.3.0 tidyverse_1.3.0 readxl_1.3.1
loaded via a namespace (and not attached):
[1] tidyselect_1.1.0 haven_2.2.0 lattice_0.20-38 colorspace_1.4-1 vctrs_0.3.2
[6] generics_0.0.2 blob_1.2.1 utf8_1.1.4 rlang_0.4.7 pillar_1.4.6
[11] glue_1.4.0 withr_2.1.2 bit64_0.9-7 dbplyr_1.4.2 modelr_0.1.5
[16] distributional_0.1.0 lifecycle_0.2.0 munsell_0.5.0 anytime_0.3.7 gtable_0.3.0
[21] progressr_0.6.0 cellranger_1.1.0 rvest_0.3.5 RDCOMClient_0.93-0 fansi_0.4.0
[26] broom_0.5.4 Rcpp_1.0.3 scales_1.1.0 backports_1.1.5 jsonlite_1.6.1
[31] bit_1.1-15.2 farver_2.0.1 fs_1.5.0 hms_0.5.2 digest_0.6.25
[36] stringi_1.5.3 grid_3.6.1 cli_2.0.2 tools_3.6.1 magrittr_1.5
[41] crayon_1.3.4 pkgconfig_2.0.3 ellipsis_0.3.0 xml2_1.3.2 reprex_0.3.0
[46] assertthat_0.2.1 httr_1.4.1 rstudioapi_0.11 R6_2.4.1 nlme_3.1-140
[51] compiler_3.6.1 下面是我在控制台中调用head()函数时选择的文件列的预览,为了保护知识产权,对其进行了匿名处理。
MFMCU MFLITM IMDSC1 MFAN8 IMUOM1 UMCONVF
1 PBK0100 123456 product<U+00AE> 559286 DR 50 发布于 2021-01-27 11:00:05
在进一步阅读之后,这就是我找到的解决方案。
我意识到我在相关专栏中混合了各种编码。
table(stri_enc_mark(forecast.file$IMDSC1))
ASCII UTF-8
658 184UTF-8项是注册商标unicode未被R识别的行。
有两种方法可以解决这个问题。
Encoding(forecast.file$IMSDSC1) <- "latin1"
forecast.file$IMDSC1 <- iconv(forecast.file$IMDSC1, from = "latin1", to = "UTF-8")也可以根据Force character vector encoding from "unknown" to "UTF-8" in R进行选择
您可以写入csv并将其读回,并将latin-1指定为编码类型。
library(data.table)
fwrite(forecast.file, "temp.csv")
forecast.file <- fread("temp.csv", encoding = "Latin-1")https://stackoverflow.com/questions/65906369
复制相似问题