Hello everybody,
maybe someone has an idea how to solve my problem.
I have a data frame and it contains all GeneIDs and a value for these genes. Like this:
all_genes (around 23000 rows)
GeneID | Value |
---|---|
Gene1 | 4 |
Gene2 | 2 |
Gene3 | 9 |
Gene4 | 0 |
Gene5 | 2 |
I also have a list of GeneIDs: Genelist <- c(Gene2, Gene4, Gene5). Finally my Genelist will be a few thousand genes long. I would like to delete all rows, which contain a gene from the Genelist to get this:
GeneID | Value |
---|---|
Gene1 | 4 |
Gene3 | 0 |
I tried to use setdiff, but this only works if you specify a column.
Something like all_genes[-grep(Genelist, all_genes$GeneID)] only works for 1 gene and not for several ones.
This is the only way i can make it work, but it takes rather long.
for (i in 1:length(Genelist)){
all_genes <- all_genes[all_genes$GeneID != Genelist[i], ]
}
OR
for (i in 1:length(Genelist)){
all_genes <- all_genes[-(all_genes$GeneID == Genelist[i]), ]
}
I'd be very happy for some advise, because i face this problem more frequently in different setups.
Thanks a lot, Alex