在 R 和 plot() 中读取阿拉伯数据文本 [英] Reading arabic data text in R and plot()

查看:21
本文介绍了在 R 和 plot() 中读取阿拉伯数据文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R 似乎不能很好地处理阿拉伯文本.虽然可以输入一些阿拉伯字符串,如

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

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

现在我使用 word 或 excel 编写更长的名称列表并将文件另存为文本.我可以在 R (RStudio) 中导入文件并正确显示导入的数据.但是,我无法操作导入的列表.例如,绘图会产生有趣的角色.为什么可以绘制直接键入的列表(一点也不简单),而不能绘制导入的列表?

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?

我使用 Windows 7、R v.3.0.2 和 RStudio 来读取文件.

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

任何有关在 R 中使用阿拉伯语文本的帮助将不胜感激.谢谢

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

推荐答案

如果您使用编码UTF-8"保存文本(例如使用 Rstudio,创建一个文本文件,然后从菜单中使用使用编码保存..."并选择UTF-8),然后就可以轻松阅读了:

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] "\"سليم\" \"سعيد\" \"مجدى\""

或者使用scan:

scan("arabic",encoding='UTF-8',what='character',sep=',')
Read 3 items
[1] "سليم"    " سعيد"   " مجدى  "

这篇关于在 R 和 plot() 中读取阿拉伯数据文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆