我似乎无法弄清楚这一点,我想读取一个包含阿拉伯字符的 csv 文件,但它没有正确读取它。
这是我的 sessionInfo
R version 3.2.4 Revised (2016-03-16 r70336)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.4.3 plyr_1.8.3
loaded via a namespace (and not attached):
[1] magrittr_1.5 R6_2.1.2 assertthat_0.1 parallel_3.2.4 DBI_0.3.1 tools_3.2.4
[7] Rcpp_0.12.4
我试过这个
ar <- read.csv (file.choose(), encoding = "UTF-8")
和这个
ar <- read.csv (file.choose(), encoding = "Windows-1256")
它对我不起作用,我也尝试将语言环境设置为阿拉伯语但没有运气
Sys.setlocale("LC_ALL","Arabic")
有什么建议?
最佳答案
您可以使用 readLines
读取文件与参数 warn = FALSE
,然后执行 read.csv
与 text
参数设置为 readLines
的结果如下。
阿拉伯文.csv 内容 :
LabelName,Label1,Label2,SpeciesLabel,Group,Subgroup,Species
التسمية 1,Group 1,Subgroup 1,Species 1,1,1,1
التسمية 2,Group 1,Subgroup 1,Species 1,1,1,1
التسمية 3,Group 1,Subgroup 1,Species 1,1,1,1
读取csv文件的R代码 :
arabic <- readLines("arabic.csv", warn = FALSE, encoding = "UTF-8")
Data <- read.csv(text = arabic)
str(Data)
Output:
'data.frame': 3 obs. of 7 variables:
$ X.U.FEFF.LabelName: Factor w/ 3 levels "التسمية 1","التسمية 2",..: 1 2 3
$ Label1 : Factor w/ 1 level "Group 1": 1 1 1
$ Label2 : Factor w/ 1 level "Subgroup 1": 1 1 1
$ SpeciesLabel : Factor w/ 1 level "Species 1": 1 1 1
$ Group : int 1 1 1
$ Subgroup : int 1 1 1
$ Species : int 1 1 1
关于r - 阿拉伯文本CSV文件导入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36446121/