Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading arabic data text in R and plot()

Tags:

text

r

arabic

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

like image 281
Shabana Avatar asked Jan 20 '14 16:01

Shabana


1 Answers

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] "سليم"    " سعيد"   " مجدى  "
like image 65
agstudy Avatar answered Oct 16 '22 23:10

agstudy