在R中使用fromJSON时处理NaN [英] Handling NaN when using fromJSON in R

查看:206
本文介绍了在R中使用fromJSON时处理NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用R中的fromJSON函数读取提供给我的JSON文件,但是此文件中包含NaN,我无法正确读取.

I'm trying to use the fromJSON function in R to read in a JSON file that was given to me, however this file has NaN in it and I can't read it in properly.

这是我得到的错误:

Error in feed_push_parser(buf) : 
  lexical error: invalid char in json text.

有人知道将json文件读入R时如何读取NaN值吗?

Anyone know how to read NaN values when reading in a json file into R?

推荐答案

我遇到了类似的问题.要解决此问题,您可以尝试以下对我有用的方法之一. i)在np ++中打开JSON文件,并用"NA"(带引号)将NaN替换为任何值.否则,R会将NaN误认为是期望为"NA"的数值.通过将NaN替换为"NA",R会将"NA"读取为字符.

I had similar problem. To resolve this, you can try one of the below as it worked for me. i) Open JSON file in np++ and replace any value with NaN with "NA" (quoted). Otherwise R misunderstands NaN as numeric value which is expected as "NA". By replacing NaN as "NA", R reads "NA" as character.

ii)将JSON文件转换为csv,并使用read.csv()命令在R中加载csv文件.

ii) convert the JSON file to csv and load the csv file in R using read.csv() command.

这篇关于在R中使用fromJSON时处理NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆