R语言中RStudio中文读取乱码的解决方法
这期内容当中小编将会给大家带来有关R语言中RStudio中文读取乱码的解决方法,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
市中网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联公司2013年至今到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司。
RStudio中使用rjson包读取处理json数据时,遇到中文会显示为 ““等类似乱码。
解决方案,在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" [2] "Operations" [3] "IT" [4] "HR" [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中文读取乱码的解决方法了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。
网站标题:R语言中RStudio中文读取乱码的解决方法
网页链接:http://ybzwz.com/article/pghoci.html