R programming: match ID in a column and extract all the matching rows
1
4
Entering edit mode
9.7 years ago
MAPK ★ 2.1k

Hi everyone,

I have this dataframe below(df1). I want to first match rs44444 in mafid and then 0/1 and 1/1 across all the genotypes (GT) samples (,GT1:GT4). and extract only the matching row and columns that has this result:

result

mafid      GT.2    GT.3    GT.4
rs44444    1/1     0/1     0/1

df1

mafid      GT.1    GT.2    GT.3    GT.4
rs44444    0/0     1/1     0/1     0/1
NA
rs44554    0/1     1/1     0/1     0/0

Thank you

dataframe R • 6.3k views
ADD COMMENT
2
Entering edit mode
9.7 years ago

This sort of thing is a bit simpler in long rather than wide format. This assumes that there's only one matching row, since it's unclear what you would want to happen were that not the case.

df2 <- df1[df1$mafid=="rs44444",]
df2 <- df2[df2 != "0/0"]
ADD COMMENT

Login before adding your answer.

Traffic: 1551 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6