我在R中有一个数据表,看起来像:
基因群体颜色覆盖率A_1 PopA Blue 0.016A_1 PopA Green 0.022A_1 PopB Blue 0.1322A_1 PopB Green 0.552A_2 PopA Blue 0.13A_2 PopA Green 0.14A2 …
一个选项 dplyr 将会
dplyr
library(dplyr) my.df %>% group_by(Gene, Population) %>% summarize(Coverage = Coverage[Color == "Blue"] - Coverage[Color == "Green"]) # A tibble: 4 x 3 # Groups: Gene [?] # Gene Population Coverage # <fct> <fct> <dbl> # 1 A_1 PopA -0.00600 # 2 A_1 PopB -0.420 # 3 A_2 PopA -0.01 # 4 A_2 PopB 0.100
的 数据 强>
my.df <- structure(list(Gene = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("A_1", "A_2"), class = "factor"), Population = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L), .Label = c("PopA", "PopB"), class = "factor"), Color = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("Blue", "Green"), class = "factor"), Coverage = c(0.016, 0.022, 0.1322, 0.552, 0.13, 0.14, 1, 0.9)), class = "data.frame", row.names = c(NA, -8L))