R programming: match ID in a column and extract all the matching rows
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
• 6,688 views
•
link
1 answer
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"]
• 0 views
•
link
Log in to answer this question.