大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这期内容当中小编将会给大家带来有关R语言中RStudio中文读取乱码的解决方法,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
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中文读取乱码的解决方法了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联-成都网站建设公司行业资讯频道。