Вы можете использовать tapply
, что дает вам хорошую матрицу.
with(dat, tapply(Disease, list(Variant_ID, Disease), length))
# Control Yes
# 2:4324:2343 2 3
# 3:346543:345 2 2
# 6:234:34234 2 2
Данные:
dat <- structure(list(Variant_ID = structure(c(1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("2:4324:2343", "3:346543:345",
"6:234:34234"), class = "factor"), PID = structure(c(2L, 3L,
4L, 5L, 6L, 2L, 6L, 7L, 8L, 6L, 7L, 6L, 1L), .Label = c("FF213",
"FF354", "FF355", "FF356", "FF357", "FF358", "FF390", "FF391"
), class = "factor"), Disease = structure(c(2L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L), .Label = c("Control", "Yes"), class = "factor")), class = "data.frame", row.names = c(NA,
-13L))