解析R中dataframe列中的json数据
我试图解析位于我的数据框架的一列中的json数据 我希望取消该列中的数据列表,并为json数据中的每个键创建特定的列解析R中dataframe列中的json数据,r,json,dataframe,R,Json,Dataframe,我试图解析位于我的数据框架的一列中的json数据 我希望取消该列中的数据列表,并为json数据中的每个键创建特定的列 由于我无法正确读取您的数据,因此我假设您的表名为:表,列名为:方法学 Methodology {"first_value":332.76,"last_value":335.05} {"first_value":573.5,"last_value":573.5} {"first_value":42.63,"last_value":42.63} {"first_value":0.44
由于我无法正确读取您的数据,因此我假设您的表名为:表,列名为:方法学
Methodology
{"first_value":332.76,"last_value":335.05}
{"first_value":573.5,"last_value":573.5}
{"first_value":42.63,"last_value":42.63}
{"first_value":0.44,"last_value":0.44}
{"first_value":0.0,"last_value":0.0}
{"first_value":92.0,"last_value":92.0}
library(jsonlite)
json <- lapply( paste0("[", Table$Methodology, "]" ),
function(x) jsonlite::fromJSON(x)
)
##json is a list which you have to unlist and form a dataframe
##you have to set the nrow for your convenience
d <- data.frame(matrix(unlist(json), nrow=100, byrow=T))
请用dput(head(my_data.frame))插入一点数据,而不是数据的图片。我们不能用图片。还有你已经试过的。请阅读。
head(df)
X1 X2
1 332.76 335.05
2 573.50 573.50
3 42.63 42.63
4 0.44 0.44
5 0.00 0.00
6 92.00 92.00