Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将R数据帧转换为JSON_R_Json_Jsonlite - Fatal编程技术网

将R数据帧转换为JSON

将R数据帧转换为JSON,r,json,jsonlite,R,Json,Jsonlite,你好!我有一个R数据帧,格式如下: user_id email segment name 123 a@gmail.com new a 234 b@gmail.com old b 如何将其转换为具有所需输出的JSON: [ { "user_id": "123", "email": "a@gmail.com", "custom_data": {

你好!我有一个R数据帧,格式如下:

   user_id   email      segment name
     123    a@gmail.com   new     a
     234    b@gmail.com   old     b
如何将其转换为具有所需输出的JSON:

[
      {
        "user_id": "123",
        "email": "a@gmail.com",
        "custom_data": {
          "segment": "new"
        },
        "tags": [
          { "name": "a" }
        ]
      },
      {
        "user_id": "234",
        "email": "b@gmail.com",
        "custom_data": {
          "segment": "old"
        },
        "tags": [
          { "name": "b" }
        ]
      }
    ]

我正在使用jsonlite包。

使用带有嵌入式
数据的列表列。frame
s:

dat