【发布时间】:2017-06-26 10:29:15
【问题描述】:
我有一个包含 JSON 格式的事件数据(用户与应用交互的点击数据)的文件,我需要将其转换为数据框。我用这个:
require(RJSONIO)
result <- fromJSON('events_data.json',nullValue = NA)
result <- do.call(rbind,lapply(result,data.frame,stringsAsFactors=FALSE))
产生这个结果
summary(result)
Length Class Mode
_id 1 -none- character
session 2 -none- list
metrics 0 -none- list
arrival_timestamp 1 -none- character
event_type 1 -none- character
event_timestamp 1 -none- character
event_version 1 -none- character
application 7 -none- list
client 2 -none- character
device 4 -none- list
attributes 3 -none- character
当我尝试将此列表转换为数据框时出现错误
Error in data.frame(locale = c("US", "en_US", "en"), platform = c("5.1.1", :
arguments imply differing number of rows: 3, 2, 1
这是数据文件,click here(仅供参考)。有人可以帮我吗。 JSON 文件包含
{"_id":{"$oid":"57a30ce268fd0809ec4d194f"},"session":{"start_timestamp":{"$numberLong":"1470183490481"},"session_id":"def5faa9-20160803-001810481"},"metrics":{},"arrival_timestamp":{"$numberLong":"1470183523054"},"event_type":"OfferViewed","event_timestamp":{"$numberLong":"1470183505399"},"event_version":"3.0","application":{"package_name":"com.think.vito","title":"Vito","version_code":"5","app_id":"7ffa58dab3c646cea642e961ff8a8070","cognito_identity_pool_id":"us-east-1:4d9cf803-0487-44ec-be27-1e160d15df74","version_name":"2.0.0.0","sdk":{"version":"2.2.2","name":"aws-sdk-android"}},"client":{"cognito_id":"us-east-1:2e26918b-f7b1-471e-9df4-b931509f7d37","client_id":"ee0b61b0-85cf-4b2f-960e-e2aedef5faa9"},"device":{"locale":{"country":"US","code":"en_US","language":"en"},"platform":{"version":"5.1.1","name":"ANDROID"},"make":"YU","model":"AO5510"},"attributes":{"Category":"120000","CustomerID":"4078","OfferID":"45436"}}
{"_id":{"$oid":"57a30ce268fd0809ec4d1950"},"session":{"start_timestamp":{"$numberLong":"1470183490481"},"session_id":"def5faa9-20160803-001810481"},"metrics":{},"arrival_timestamp":{"$numberLong":"1470183523054"},"event_type":"ContextMenuItemSelected","event_timestamp":{"$numberLong":"1470183500206"},"event_version":"3.0","application":{"package_name":"com.think.vito","title":"Vito","version_code":"5","app_id":"7ffa58dab3c646cea642e961ff8a8070","cognito_identity_pool_id":"us-east-1:4d9cf803-0487-44ec-be27-1e160d15df74","version_name":"2.0.0.0","sdk":{"version":"2.2.2","name":"aws-sdk-android"}},"client":{"cognito_id":"us-east-1:2e26918b-f7b1-471e-9df4-b931509f7d37","client_id":"ee0b61b0-85cf-4b2f-960e-e2aedef5faa9"},"device":{"locale":{"country":"US","code":"en_US","language":"en"},"platform":{"version":"5.1.1","name":"ANDROID"},"make":"YU","model":"AO5510"},"attributes":{"MenuItem":"OfferList","CustomerID":"4078"}}
【问题讨论】:
-
什么错误?您是如何尝试转换的?
-
PS - 你不能指望人们下载一个 130MB 的文件。在问题本身中发布一个内容的小示例
-
也许有帮助...请阅读有关minimal 和reproducible 的问题。欢迎来到 SO!当您阅读并注意这两个简短的指南时,问题得到回答的可能性要高得多(甚至更快)。否则你的问题一定会被忽略、关闭或回答错误,这些都对你没有帮助。
-
刚刚再次更新了我的问题,提供了更多细节。
-
您的 sn-p 不是有效的 JSON,因为项目必须在
[]或{}容器中以逗号分隔。请包含适当的几行数据,以便我们重现。