jmich738
jmich738

Reputation: 1675

R problems with non-English characters

I'm getting some location info from Twitter and I can't get the foreign language characters to come out right when I convert the list into data frame. For example, I have this code:

x <- rbind('МоскваРоссия','knoxfieldmelbourne', 'CA US','MelbrneAustralia')
y <- data.frame(rbind('МоскваРоссия','knoxfieldmelbourne', 'CA US','MelbrneAustralia'))

write.csv(x,'\\test2.csv')

If I just read out 'x' in the console I get:

> x
     [,1]                
[1,] "МоскваРоссия"      
[2,] "knoxfieldmelbourne"
[3,] "CA US"             
[4,] "MelbrneAustralia"  

But when I write X into csv or when I look at it in viewer I get: enter image description here

I'm running on Windows and using Excel to open CSV file.

If I run 'y' in the console I get the same result as above. Obviously R can read non-English characters but why does it change when I copy it to csv?

Upvotes: 2

Views: 2013

Answers (1)

user3675152
user3675152

Reputation: 23

Those are Russian characters. Unless you're working with a lot of different languages and don't know which is which, simply changing the R locale should work. Also, the file encoding needs to be UTF.

Sys.setlocale(locale = "Russian")
write.csv(x,'\\test2.csv',fileEncoding = "UTF-8")

Upvotes: 1

Related Questions