fromJSON
返回一个列表,您可以使用
*apply
函数来遍历每个元素。将其转换为“表”非常简单(一旦您知道该怎么做!)(数据框是正确的R术语)。
library(rjson)# You can pass directly the filenamemy.JSON <- fromJSON(file="test.json")df <- lapply(my.JSON, function(play) # Loop through each "play" { # Convert each group to a data frame. # This assumes you have 6 elements each time data.frame(matrix(unlist(play), ncol=6, byrow=T)) })# Now you have a list of data frames, connect them together in# one single dataframedf <- do.call(rbind, df)# Make column names nicer, remove row namescolnames(df) <- names(my.JSON[[1]][[1]])rownames(df) <- NULLdf wins losses max_killed battles plane_id max_ground_object_destroyed1 118 40 7 158 4401 32 100 58 7 158 2401 33 120 38 7 158 2403 34 12 450 7 158 4401 35 150 8 7 158 2401 36 120 328 7 158 2403 3