Handling NaN when using fromJSON in R

瘦欲@ 提交于 2019-12-13 14:13:56

问题


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.

This is the error I get:

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

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


回答1:


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) convert the JSON file to csv and load the csv file in R using read.csv() command.



来源:https://stackoverflow.com/questions/31955051/handling-nan-when-using-fromjson-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!