问题
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