您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關R語言中RStudio中文讀取亂碼的解決方法,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
RStudio中使用rjson包讀取處理json數據時,遇到中文會顯示為 “<U+4EBA>“等類似亂碼。
解決方案,在R語言終端中輸入以下命令完美解決。
Sys.setlocale(category="LC_ALL",locale="en_US.UTF-8")
將以下JSON數據保存為json格式文件(注意文件編碼為UTF-8)
{ "ID": ["1", "2", "3", "4", "5", "6", "7", "8"], "Name": ["Rick", "Dan", "Michelle", "Ryan", "Gary", "Nina", "Simon", "Guru"], "Salary": ["623.3", "515.2", "611", "729", "843.25", "578", "632.8", "722.5"], "StartDate": ["1/1/2012", "9/23/2013", "11/15/2014", "5/11/2014", "3/27/2015", "5/21/2013", "7/30/2013", "6/17/2014"], "Dept": ["IT部門", "Operations", "IT", "HR人力資源部", "Finance", "IT", "Operations", "Finance"] }
使用rjson包讀取json數據,已下3行命令:
library("rjson") result_json <- fromJSON(file = "comment.json") result_json
第一行:加載rjson包;
第二行:使用函數fromJSON讀取本地json文件;
第三行:輸出結果;
在未解決亂碼之前輸出結果是:
$ID [1] "1" "2" "3" "4" "5" "6" "7" "8" $Name [1] "Rick" "Dan" "Michelle" "Ryan" [5] "Gary" "Nina" "Simon" "Guru" $Salary [1] "623.3" "515.2" "611" "729" "843.25" "578" [7] "632.8" "722.5" $StartDate [1] "1/1/2012" "9/23/2013" "11/15/2014" "5/11/2014" [5] "3/27/2015" "5/21/2013" "7/30/2013" "6/17/2014" $Dept [1] "IT<U+90E8><U+95E8>" [2] "Operations" [3] "IT" [4] "HR<U+4EBA><U+529B><U+8D44><U+6E90><U+90E8>" [5] "Finance" [6] "IT" [7] "Operations" [8] "Finance"
通過命令解決中文輸出問題后,輸出結果完美解決中文問題。
$ID [1] "1" "2" "3" "4" "5" "6" "7" "8" $Name [1] "Rick" "Dan" "Michelle" "Ryan" [5] "Gary" "Nina" "Simon" "Guru" $Salary [1] "623.3" "515.2" "611" "729" "843.25" "578" [7] "632.8" "722.5" $StartDate [1] "1/1/2012" "9/23/2013" "11/15/2014" "5/11/2014" [5] "3/27/2015" "5/21/2013" "7/30/2013" "6/17/2014" $Dept [1] "IT部門" "Operations" "IT" [4] "HR人力資源部" "Finance" "IT" [7] "Operations" "Finance"
上述就是小編為大家分享的R語言中RStudio中文讀取亂碼的解決方法了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。