问题描述
我在Rstudio控制台中无法显示俄语字符.我使用readxl软件包用俄语加载Excel文件.西里尔字母正确显示在数据框中.但是,如果我运行的函数的输出包含变量名,则RStudio控制台将显示符号,而不是正确的西里尔字符.
I am having trouble displaying Russian characters in the Rstudio console. I load an Excel file with Russian using the readxl package. The cyrillic displays properly in the dataframe. However, if I run a function that has an output that includes the variable names, the RStudio consoles displays symbols instead of the proper Cyrillic characters.
test.xlsx包含两列-зависимаяпеременная(因变量-数字)和независимаяпеременная(因变量,因子).
test.xlsx contains two columns - зависимая переменная (dependent variable - numeric) and независимая переменная (independent variable, factor).
зависимая_переменная независимая_переменная
5 а
6 б
8 в
8 а
7.5 б
6 в
5 а
4 б
3 в
2 а
5 б
我的代码:
Sys.setlocale(locale = "Russian")
install.packages("readxl")
require(readxl)
basetable <- readxl::read_excel('test.xlsx',sheet = 1)
View(basetable)
basetable$независимая_переменная <- as.factor(basetable$независимая_переменная)
str(basetable)
这是我从str函数的输出中得到的:
This is what I get for the output of the str function:
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 11 obs. of 2 variables:
$ çàâèñèìàÿ_ïåðåìåííàÿ : num 5 6 8 8 7.5 6 5 4 3 2 ...
$ íåçàâèñèìàÿ_ïåðåìåííàÿ: Factor w/ 3 levels "а","б","в": 1 2 3 1 2 3 1 2 3 1 ...
我想用俄语正确显示变量名,因为我将从这些数据中构建许多模型.供参考,这是我的sessionInfo()
I want to have the variable names displayed properly in Russian because I will be building many models from this data. For reference, here is my sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=Russian_Russia.1251 LC_CTYPE=Russian_Russia.1251
[3] LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C
[5] LC_TIME=Russian_Russia.1251
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] readxl_0.1.1 shiny_0.13.1 dplyr_0.4.3
loaded via a namespace (and not attached):
[1] Rcpp_0.12.2 digest_0.6.9 assertthat_0.1 mime_0.4
[5] chron_2.3-47 R6_2.1.2 xtable_1.8-2 jsonlite_0.9.19
[9] DBI_0.3.1 magrittr_1.5 lazyeval_0.1.10 data.table_1.9.6
[13] tools_3.2.3 httpuv_1.3.3 parallel_3.2.3 htmltools_0.3
推荐答案
尝试将编码的数据框名称更改为UTF-8.
Try to change dataframe colnames encoding to UTF-8.
Encoding(colnames(YOURDATAFRAME)) <- "UTF-8"
这篇关于在RStudio控制台中显示西里尔字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!