官术网_书友最值得收藏!

Loading the jsonlite package

The following command is executed to include the jsonlite package in the R workspace:

library(jsonlite)

Data processing or parsing is done through a process called simplification. This is where JSON arrays are converted from a list into a more specific R class. Basically, with a simplification process, the arrays are broken down into values that can be easily understood. There are three different options that can be passed as arguments to the fromJSON function:

  • simplifyVector: This option is used to convert arrays into a vector format
  • simplifyDataFrame: This option is used to convert arrays into a data frame format with representation of rows and columns
  • simplifyMatrix: This is similar to the data frame format, the only difference being that data should be included as a numeric representation

Let's look at an example of a data frame:

json_data <-
'[
  {"Name" : "John", "Age" : 42, "City" : "New York"}, 
  {"Name" : "Jane", "Age" : 41, "City" : "Paris"},
  {},
  {"Name" : "Bob", "City" : "London"}
]'
df <- fromJSON(json_data)
df

Here, json_data key values are converted into a data frame.

主站蜘蛛池模板: 弥勒县| 巨野县| 平乐县| 上思县| 固安县| 梓潼县| 云南省| 左权县| 太和县| 邵阳市| 都匀市| 信宜市| 灵宝市| 罗江县| 囊谦县| 台南县| 兰坪| 宣城市| 龙川县| 余姚市| 永修县| 穆棱市| 红桥区| 砀山县| 武义县| 丘北县| 方山县| 肇源县| 政和县| 游戏| 岳普湖县| 老河口市| 大厂| 涞水县| 施秉县| 措勤县| 澳门| 新源县| 昭觉县| 伊通| 亳州市|