這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)R語言中RStudio中文讀取亂碼的解決方法,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
10年積累的成都網(wǎng)站建設(shè)、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有青河免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。RStudio中使用rjson包讀取處理json數(shù)據(jù)時(shí),遇到中文會(huì)顯示為 “<U+4EBA>“等類似亂碼。
解決方案,在R語言終端中輸入以下命令完美解決。
Sys.setlocale(category="LC_ALL",locale="en_US.UTF-8")
將以下JSON數(shù)據(jù)保存為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數(shù)據(jù),已下3行命令:
library("rjson") result_json <- fromJSON(file = "comment.json") result_json
第一行:加載rjson包;
第二行:使用函數(shù)fromJSON讀取本地json文件;
第三行:輸出結(jié)果;
在未解決亂碼之前輸出結(jié)果是:
$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"
通過命令解決中文輸出問題后,輸出結(jié)果完美解決中文問題。
$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中文讀取亂碼的解決方法了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道。
本文標(biāo)題:R語言中RStudio中文讀取亂碼的解決方法-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://vcdvsql.cn/article40/dgojeo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、標(biāo)簽優(yōu)化、小程序開發(fā)、網(wǎng)站排名、域名注冊(cè)、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容