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

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.

主站蜘蛛池模板: 定日县| 喀喇沁旗| 莎车县| 贵溪市| 堆龙德庆县| 东港市| 益阳市| 土默特右旗| 云南省| 潞城市| 确山县| 黔西| 岳阳市| 米泉市| 临颍县| 灵宝市| 全南县| 商河县| 新安县| 新田县| 平山县| 徐州市| 朔州市| 广河县| 宣汉县| 上林县| 连平县| 东莞市| 舒兰市| 东源县| 宽甸| 富平县| 安丘市| 平顺县| 神农架林区| 哈密市| 丹江口市| 玛纳斯县| 易门县| 五常市| 平原县|