从几个对象的列表中获取唯一的中值。

时间:2014-12-12 16:03:10

标签: r list median

我有3个包含生物量值的对象列表。我想从这个列表中提取一个唯一值,该值对应于3个对象内所有森林生物量值的中值。我认为这很简单,但不知何故无法达到目标。有人可以帮助我吗?谢谢你的帮助。

dput(x)
list(structure(c(3.37515461444855, 5.19044327735901, 3.22319519519806, 
5.68365132808685, 2.36871695518494, 2.36871695518494, 3.63608360290527, 
2.99963092803955, 10.2748856544495, 10.2748856544495, 16.4309034347534, 
22.3492307662964, 12.4613256454468, 0, 2.03538191318512, 1.07113289833069, 
21.3975343704224, 15.1670708656311, 4.22249209880829, 7.37385129928589, 
14.4166820049286, 14.3547036647797, 0, 7.37385129928589, 7.05217242240906, 
7.05217242240906, 3.68692564964294, 7.05217242240906, 6.73049354553223, 
7.05217242240906, 3.67388677597046, 25.9837236404419, 45.9836235046387, 
33.4825744628906, 1.5435653924942, 10.1114643216133, 45.6102886199951, 
10.1114643216133, 31.958158493042, 45.2369537353516, 45.2369537353516, 
18.6793632507324, 18.6793632507324, 21.7280540466309, 19.710410118103
), .Dim = c(45L, 1L), .Dimnames = list(NULL, "Forest_Biomass_2000")), 
    structure(c(14.4797344207764, 2.04780006408691, 0, 0, 13.7020168304443, 
    0, 0, 0.32373720407486, 22.9602508544922, 11.6327629089355, 
    0, 4.97857093811035, 5.25019407272339), .Dim = c(13L, 1L), .Dimnames = list(
        NULL, "Forest_Biomass_2000")), structure(NA_real_, .Dim = c(1L, 
    1L), .Dimnames = list(NULL, "Forest_Biomass_2000")))

1 个答案:

答案 0 :(得分:1)

怎么样

median(unlist(x), na.rm = TRUE)
#[1] 7.052172

评论后编辑

y <- unlist(x)
q <- quantile(y, na.rm = TRUE)
median(y[y > q[4]], na.rm = TRUE)
#[1] 22.96025

这是你的意思吗?