[
{
"type": ["MixedExponential"],
"mean": [16105.5],
"sd": [44733.7177],
"means": [2456, 545, 83553, 2432, 65546],
"weights": [0.2, 0.4, 0.1, 0.2, 0.1]
},
{
"type": ["Normal"],
"mean": [15000],
"sd": [10000]
},
{
"type": ["LogNormal"],
"mean": [162754.7914],
"sd": [1191540.1555],
"logmu": [10],
"logsd": [2]
},
{
"type": ["PiecewiseLinear"],
"mean": [2553.25],
"sd": [3391.1389],
"points": [
{
"x": 0,
"Fx": 0
},
{
"x": 0,
"Fx": 0.05
},
{
"x": 50,
"Fx": 0.06
},
{
"x": 100,
"Fx": 0.1
},
{
"x": 200,
"Fx": 0.3
},
{
"x": 500,
"Fx": 0.35
},
{
"x": 1000,
"Fx": 0.5
},
{
"x": 1000,
"Fx": 0.6
},
{
"x": 2000,
"Fx": 0.7
},
{
"x": 5000,
"Fx": 0.79
},
{
"x": 10000,
"Fx": 0.9
},
{
"x": 10000,
"Fx": 1
}
],
"scale": [1],
"point_masses": [
{
"x": 0,
"Fx": 0.05
},
{
"x": 1000,
"Fx": 0.1
},
{
"x": 10000,
"Fx": 0.1
}
],
"length": [12]
}
]
这就是我的JSON数据的样子。
因此,我需要将其转换为包含4个对象的列表。 在最后一个对象中,我需要“点”和“ point_masses”为data.frames。其他所有属性都应该只是一个原子向量。
我显然尝试使用:
jsonlite::fromJSON()
但是它不起作用。它将整个事情变成一个data.frame。而且数据似乎混乱了:
type mean sd means weights logmu logsd
1 MixedExponential 16105.5 44733.72 2456, 545, 83553, 2432, 65546 0.2, 0.4, 0.1, 0.2, 0.1 NULL NULL
2 Normal 15000 10000 NULL NULL NULL NULL
3 LogNormal 162754.8 1191540 NULL NULL 10 2
4 PiecewiseLinear 2553.25 3391.139 NULL NULL NULL NULL
points
1 NULL
2 NULL
3 NULL
4 0.0e+00, 0.0e+00, 5.0e+01, 1.0e+02, 2.0e+02, 5.0e+02, 1.0e+03, 1.0e+03, 2.0e+03, 5.0e+03, 1.0e+04, 1.0e+04, 0.0e+00, 5.0e-02, 6.0e-02, 1.0e-01, 3.0e-01, 3.5e-01, 5.0e-01, 6.0e-01, 7.0e-01, 7.9e-01, 9.0e-01, 1.0e+00
scale point_masses length
1 NULL NULL NULL
2 NULL NULL NULL
3 NULL NULL NULL
4 1 0e+00, 1e+03, 1e+04, 5e-02, 1e-01, 1e-01 12
这是预期的输出:
[[1]]
[[1]]$`type`
[1] "MixedExponential"
[[1]]$mean
[1] 16105.5
[[1]]$sd
[1] 44733.72
[[1]]$means
[1] 2456 545 83553 2432 65546
[[1]]$weights
[1] 0.2 0.4 0.1 0.2 0.1
[[2]]
[[2]]$`type`
[1] "Normal"
[[2]]$mean
[1] 15000
[[2]]$sd
[1] 10000
[[3]]
[[3]]$`type`
[1] "LogNormal"
[[3]]$mean
[1] 162754.8
[[3]]$sd
[1] 1191540
[[3]]$logmu
[1] 10
[[3]]$logsd
[1] 2
[[4]]
[[4]]$`type`
[1] "PiecewiseLinear"
[[4]]$mean
[1] 2553.25
[[4]]$sd
[1] 3391.139
[[4]]$points
x Fx
1 0 0.00
2 0 0.05
3 50 0.06
4 100 0.10
5 200 0.30
6 500 0.35
7 1000 0.50
8 1000 0.60
9 2000 0.70
10 5000 0.79
11 10000 0.90
12 10000 1.00
[[4]]$scale
[1] 1
[[4]]$point_masses
x Fx
1 0 0.05
2 1000 0.10
3 10000 0.10
[[4]]$length
[1] 12