0
$\begingroup$

I have a dataframe like this

> dim(anno_maf)
[1] 32786   129
> head(anno_maf[1:2,1:4])
   Tumor_Sample_Barcode Chromosome Start_Position
1:                    a       chr1       27105930
2:                    a       chr1        3342771
   End_Position
1:     27105930
2:      3342771
> 

I have a list of genes like

gene name
PTEN
PTEN
MAP3K1
MALAT1
MED12
RUNX1
PIK3CA
FBXW7
ARID1A
MED12
TAB1

I want to add a column in my dataframe named COSMIC, if a gene in gene list exists in my dataframe Hugo_Symbol column, put a yes for this gene if not put a no; Finally my data frame has an extra column as COSMIC in which I have yes or no in Hugo_Symbol column based on the existence of genes in my gene list

Can you help me please?

Thank you

$\endgroup$

1 Answer 1

2
$\begingroup$

You can use ifelse():

anno_maf$COSMIC <- ifelse(anno_maf$Hugo_Symbol %in% your_gene_list,
                          yes = "yes",
                          no = "no")
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.