Мы можем использовать dcast
из data.table
library(data.table)
dcast(setDT(data0), Sample ~ Gene)
# Sample gene1 gene2 gene3 gene4 gene5 gene6
#1: sample1 18 1 1 14 8 NA
#2: sample2 7 NA NA 10 4 NA
#3: sample3 10 NA 3 9 NA 1
Или с xtabs
из base R
xtabs(Frequency ~ Sample + Gene, data0)
данных
data0 <- structure(list(Sample = c("sample1", "sample1", "sample1", "sample1",
"sample1", "sample2", "sample2", "sample2", "sample3", "sample3",
"sample3", "sample3"), Gene = c("gene1", "gene2", "gene3", "gene4",
"gene5", "gene1", "gene4", "gene5", "gene1", "gene3", "gene6",
"gene4"), Frequency = c(18L, 1L, 1L, 14L, 8L, 7L, 10L, 4L, 10L,
3L, 1L, 9L)), class = "data.frame", row.names = c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12"))