lundi 6 août 2018

Make a loop with if to create a column [duplicate]

This question already has an answer here:

Sorry for the really basic question, I have looked everywhere but cannot find an answer. I have a data frame (d.f) looking like this:

A count A variant B count B variant
3---------G-----------2----------T
9---------A-----------2----------T
3---------A-----------8----------C

I would like to create a fifth column, and have written this code for it

if(d.f$A_count>d.f$B_count) 
 d.f$Fifth <- d.f$A_variant else
  d.f$Fifth <- d.f$B_variant

My fifth column should have G, A, C
How can I make the if condition work for my data frame, basically making a loop for every row?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire