【问题标题】:compute the breteau index with R用 R 计算 breteau 指数
【发布时间】:2019-04-30 04:47:09
【问题描述】:

这是我拥有的一个数据框,我想计算 breteau 索引

## Here is the table

commune container   house   aegypti albopictus
yde4       c1            h1    6        6
yde2       c2            h2    2        3
yde7       c3            h3    1        0
yde7       c3            h4    1        1
yde7       c5            h5    8        0
yde7       c6            h6    0        0
yde4       c7            h7    4        1
yde7       c8            h8    14       9
yde3       c9            h9    0        1
yde3       c10           h10   6        2

## here is how it should display

                                        aegypti                albopictus   
com    house_pros     c_found   Pos_container     In    Pos_container   In
yde2    1              1             1            100          1        100     
yde3    2              2             1             50          2        100
yde4    2              2             2            100          2        100
yde7    4              5             4            100          2        40
Total   9              10            8             88          7        70

`com = commune,house_pros = 预期房屋数量,c_found = 在每个社区中发现的容器数量,pos_container = 每个社区的阳性容器(至少发现一只埃及伊蚊或白纹象的容器)的数量,对于每个物种(aegypti 或 albopictus)(考虑到我们可能在房子里有多个容器), 和 In = Breteau 指数计算((阳性容器数/预期房屋数)*100。该指数是针对每个物种和每个公社计算的。并添加总计行和列。

我找不到合适的代码。

有人可以帮我选一个合适的吗?

【问题讨论】:

    标签: r indexing summarize


    【解决方案1】:

    这是使用dplyr 的一种方法,首先使用summarize 计算house_prosc_foundaegypti_Pos_container,然后使用bind_rowsTotal 的末尾追加行。对albopictus 使用相同的步骤

    library(dplyr)
    df %>% group_by(commune) %>% 
           summarise(house_pros=n_distinct(container),    #See dplyr::n_distinct
                     c_found=n(),                         # Size of each group
                     aegypti_Pos_container=sum(aegypti!=0)) %>%  #Num of aegypti !=0
           bind_rows(.,tibble(commune='Total',house_pros=sum(.$house_pros),c_found=sum(.$c_found),
                              aegypti_Pos_container=sum(.$aegypti_Pos_container))) %>% 
           mutate(aegypti_In=(aegypti_Pos_container/house_pros)*100)
    
    
    # A tibble: 5 x 5
      commune house_pros c_found aegypti_Pos_container aegypti_In
      <chr>        <int>   <int>                 <int>      <dbl>
    1 yde2             1       1                     1      100  
    2 yde3             2       2                     1       50  
    3 yde4             2       2                     2      100  
    4 yde7             4       5                     4      100  
    5 Total            9      10                     8       88.9
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-13
      • 1970-01-01
      • 2023-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      相关资源
      最近更新 更多