簡體   English   中英

R dplyr::按用戶定義的函數匯總組

[英]R dplyr::summarize groups by user defined functions

我有一個包含三個變量(基因、樣本、copy_number)的 data.frame,我想對按基因名稱分組的 copy_number 進行匯總統計。

我嘗試在 dplyr 中使用匯總 function 但一直失敗。

我想要具有或多或少特定corrected_copy_number的樣本數量

數據看起來像這樣(截斷)

> sub.melt.df.annotations.cna.genes
       Gene_Names          sample corrected_copy_number
3234        BRCA1 sample1                     6
7317        BRCA2 sample1                     1
10500       ERBB2 sample1                     4
11258       GATA3 sample1                     3
3234        GATA3 sample2                     2
7317        BRCA2 sample2                     1
10500       ERBB2 sample2                     3
.
.
11258       GeneX sampleN                     #



> sub.melt.df.annotations.cna.genes %>% group_by(Gene_Names) %>% dplyr::summarise(count=n(), min(corrected_copy_number),gain=n((corrected_copy_number>2)))
Error: Problem with `summarise()` input `gain`.
x unused argument ((corrected_copy_number > 2))
ℹ Input `gain` is `n((corrected_copy_number > 2))`.
ℹ The error occurred in group 1: Gene_Names = "BRCA1".
Run `rlang::last_error()` to see where the error occurred.

感謝您的幫助

n(corrected_copy_number>2)替換為sum(corrected_copy_number>2)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM