jeudi 2 mars 2017

R combine a new column by selecting two columns information

I have a data frame with two columns information and I would like to create a new column that based on the second column and select the content that did not contain the NA value.

df:
200610-1    rs28619217
200610-10   NA
200610-100  rs367572771
200610-102  rs144402189
200610-105  rs375896687
200610-107  NA
200610-108  NA
200610-109  NA
200610-110  rs199838004
200610-111  rs374875201
200610-112  NA
200610-113  rs377546596
200610-114  NA
200610-115  NA
200610-116  NA

desired output:
200610-1    rs28619217  rs28619217
200610-10   NA          200610-10
200610-100  rs367572771 rs367572771
200610-102  rs144402189 rs144402189
200610-105  rs375896687 rs375896687
200610-107  NA          200610-107
200610-108  NA          200610-108
200610-109  NA          200610-109
200610-110  rs199838004 rs199838004
200610-111  rs374875201 rs374875201
200610-112  NA          200610-112
200610-113  rs377546596 rs377546596
200610-114  NA          200610-114
200610-115  NA          200610-115
200610-116  NA          200610-116

what should I do step by step? I am thinking of using apply function. Thank you for your advise.

Aucun commentaire:

Enregistrer un commentaire