2017-08-03 25 views
1

Hej每個人,也許有人可以幫助我以下(在我眼裏)異常。查看(my.data)顯示正確的字符,print(my.data)不可讀

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  

回答

0

語言區域已經在中國,嘗試data <- read.table("df", sep=','fileEncoding="UTF-8-BOM")fileEncoding="UTF-8"。看看它是否有效

+0

謝謝你的回答。它不幸地返回這個錯誤:錯誤:「data < - read.table(」df「,sep =','fileEncoding」 – SCW