View(my.data)显示正确的字符,print(my.data)不可读

时间:2017-08-03 11:48:27

标签: r encoding

大家,也许有人可以帮助我以下(在我看来)异常。

Sys.setlocale(category = "LC_ALL", locale = "Chinese")
n = c(2, 3, 5) 
s = c("我", "你", "他") 
b = c(TRUE, FALSE, TRUE) 
df = data.frame(n, s, b)
View(df)

enter image description here

而控制台中的输出看起来很奇怪:

print(df)
n    s    b
2    ÎÒ   TRUE
3    Äã   FALSE
5    Ëû   TRUE

我认为在非标准编码的其他情况下也可能出现此问题 - 任何人都知道我能做什么? 最好的祝福, 斯蒂菲

PS:

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] bibliometrix_1.7 openxlsx_4.0.17  stringr_1.2.0    devtools_1.13.2  WriteXLS_4.0.0  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11         compiler_3.4.1       RColorBrewer_1.1-2   git2r_0.18.0         plyr_1.8.4          
 [6] tools_3.4.1          digest_0.6.12        memoise_1.1.0        tibble_1.3.3         gtable_0.2.0        
[11] lattice_0.20-35      rlang_0.1.1          Matrix_1.2-10        igraph_1.0.1         rstudioapi_0.6      
[16] ggrepel_0.6.5        curl_2.7             parallel_3.4.1       factoextra_1.0.4     withr_1.0.2         
[21] httr_1.2.1           cluster_2.0.6        rscopus_0.4.6        flashClust_1.01-2    grid_3.4.1          
[26] scatterplot3d_0.3-40 R6_2.2.2             ggplot2_2.2.1        FactoMineR_1.36      magrittr_1.5        
[31] scales_0.4.1         SnowballC_0.5.1      MASS_7.3-47          leaps_3.0            stringdist_0.9.4.4  
[36] colorspace_1.3-2     stringi_1.1.5        lazyeval_0.2.0       munsell_0.4.3       

1 个答案:

答案 0 :(得分:0)

由于区域设置已使用中文,请尝试data <- read.table("df", sep=','fileEncoding="UTF-8-BOM")fileEncoding="UTF-8"。看看它是否有效