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

查看:38
本文介绍了在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天全站免登陆