Folks, one simple q, which really started to piss me off seriously. How do you work with Cyrillic? How do you prepare the xlsx or csv file for proper reading in R after importing? I tried numerous options from Google, saving in different formats, using encoding, opening in notepads, putting Sys.setlocale("LC_CTYPE", "ukrainian") - NOTHING WORKS for me.
I used
Sys.setlocale("LC_CTYPE", "ukrainian")
# Set working directory
setwd("C:~AO")
# Packages
library(xlsx)
# Read file
kyiv.dfrr <- read.xlsx2(file="Kyiv DFRR.xlsx", sheetIndex = 1, stringsAsFactors = FALSE)
or
kyiv.dfrr <- read.csv("Kyiv DFRR.csv", header = TRUE)
Result
Type Planned Planned...9.months. Paid
X..paid..planned..9.months. latitude
1 ??????????? 62,821 27,344 21,875
80.0 50.43494
2 ??????????? 40,000 20,000 12,000
60.0 50.45447
3 ??????????? 50,000 50,000 14,539
29.1 50.52310
4 ???????????? 9,490 395 0
0.0 50.48074
5 ????????????????? (?????????????) 9,613 9,613 2,790
29.0 50.52318
6 ????????????? 9,821 2,000 0
0.0 50.50171
longitude Kyiv.city.district MP
1 30.54683 ?????????? ????? ?????? ?????????????
2 30.50433 ?????????????? ???????? ???? ?????????????
3 30.45902 ??????????? ????????? ?????? ???????????
4 30.40263 ?????????????? ???????? ???? ?????????????
5 30.60095 ??????????? ?????? ???????? ????????
6 30.60764 ??????????? ?????? ???????? ????????
Simple and elegant solution exists, I still have hope! Thanks!
Seems that the problem is behind your R(Studio) locale (see the reproduction code below). I would 1) use
readxlfor reading XLSX files, 2) not mess up with locales (I had the same problem with reading CSV files some time before, and instead of just settingencoding = "UTF-8"changed locale -- and it ruined the RStudio output completely -- only update of RStudio helped). So I would try to restart or reinstall RStudio (especially if you can update it at the same time :).