many to many - r find one-to-one linkage between 2 cols -
i have dataframe this
df <- data.frame(g1=c("x1","x2","x2","x3","x4"), g2=c("y1","y1","y2","y3",na), stringsasfactors = false)
each row indicates x linked y of same row.
how shall find how many x , y uniquely linked, not counting na?
like in case, 1 unique linkage x3 y3.
thanks.
as understand question, you're looking rows of data frame g1
value , g2
value both unique. can check unique values in r duplicated
function:
subset(df, !duplicated(g1) & !duplicated(g1, fromlast=true) & !is.na(g1) & !duplicated(g2) & !duplicated(g2, fromlast=true) & !is.na(g2)) # g1 g2 # 4 x3 y3
Comments
Post a Comment