Reading arabic data text in R and plot()

2019-03-16 14:25发布

R appears not to handle arabic text very well. Though it is possible to type some arabic strings like

Names <- c("سليم", "سعيد", "مجدى").

Now I use word or excel to write longer lists of name and save the file as text. I can import the file in R (RStudio) and display correctly the imported data. However, I can not manipulate the imported list. Plotting for example produces funny characters. why directly typed lists (not easy at all) can be plotted but not the imported list?

I am using windows 7, R v.3.0.2, and RStudio to read the file.

Any help on using arabic text in R will be appreciated. Thanks

标签: r text arabic
1条回答
干净又极端
2楼-- · 2019-03-16 15:15

If you save you text with encoding 'UTF-8' ( For example using Rstudio, create a text file and then from menu use "Save with encoding..." and choose UTF-8), Then you can read it easily:

readLines('d:/temp/arabic.txt',encoding='UTF-8')
[1] "\"سليم\" \"سعيد\" \"مجدى\""

Or using scan:

scan("arabic",encoding='UTF-8',what='character',sep=',')
Read 3 items
[1] "سليم"    " سعيد"   " مجدى  "
查看更多
登录 后发表回答