美文网首页
dplyr-aggregate聚合数据框

dplyr-aggregate聚合数据框

作者: 倪桦 | 来源:发表于2022-05-22 00:29 被阅读0次
    > counts
           cell.1 cell.2 cell.3 cell.4 cell.5
    gene.1      2      4      3      3      3
    gene.2      6      4      3      3      0
    gene.3      1      2      3      3      3
    gene.4      8      9      0      3      0
    
    row.agg.list <- c('x_1','x_2','x_1','x_3')
    counts %>% data.table::data.table() %>% aggregate(by=list(row.agg.list), FUN=sum) %>% 
        tibble::column_to_rownames(var = "Group.1") 
    #######################################
        cell.1 cell.2 cell.3 cell.4 cell.5
    x_1      3      6      6      6      6
    x_2      6      4      3      3      0
    x_3      8      9      0      3      0
    
    col.agg.list <- c('cll.a','cll.a','cell.b','cell.c','cell.c')
    counts %>% t() %>% data.table::data.table() %>% aggregate(by=list(col.agg.list), FUN=mean) %>% 
        tibble::column_to_rownames(var = "Group.1") %>% t()
    #######################################
           cell.b cell.c cll.a
    gene.1      3    3.0   3.0
    gene.2      3    1.5   5.0
    gene.3      3    3.0   1.5
    gene.4      0    1.5   8.5
    

    相关文章

      网友评论

          本文标题:dplyr-aggregate聚合数据框

          本文链接:https://www.haomeiwen.com/subject/xsunurtx.html