我正在尝试从 NOAA 解开天气警报。
https://api.weather.gov/alerts
library(jsonlite)
#API
string = "https://api.weather.gov/alerts"
#import json and flatten
json_data <- fromJSON(string,flatten=TRUE)
#get names
names(json_data)
[1] "@context" "type" "features" "title" "updated"
#extract the features
final_data <- as.data.table(json_data$features)
这会生成一个表格,我可以从中获取有关每个警报的详细信息。然而,一些结果被进一步嵌套。例如:
head(final_data$properties.geocode.UGC,1)
[[1]]
[1] "AMZ732" "AMZ741" "AMZ715" "AMZ725" "AMZ712" "AMZ710"
我想解压这些并旋转表格,所以每一行都应该是:
warning | properties.geocode.UGC
storm | AMZ732
storm | AMZ741
storm | AMZ715
storm | AMZ725
storm | AMZ712
storm | AMZ710
我该怎么做?它会涉及取消列出该列吗?