This is a test version of Biostars. For the public version, visit https://www.biostars.org.
R - Count number of Samples with mutation per gene

Hey,

I have an annotated VCF file in R. So basically one column with the gene name and multiple columns with the genotype (0,1,2, = WT, HET, HOM). Now I would like to summarize the number of how many individual samples have one or more mutation per gene. Any ideas on how to do that ?

Thanks!

r snp next-gen

1 answer

you can apply the function table() for each row in your VCF:

> GENE1 = c(1,2,2,2,2,0,0,1,1,1) 
> table(GENE1)
GENE1
0 1 2
2 4 4

thus the result is a vector with a counter for each genotype found in the considered gene.

Log in to answer this question.