I have a matrix called mymat . I have a vector called geno <- c("01","N1","11","1N","10") . I have another table called key.table . I want that I want to map the key column in key.table to the key column in mymat and if the column values ββin any of the corresponding rows have any of the geno elements I want to extract the name of this column from mymat along with the corresponding geno element and insert it into a new column in matched.extract in key.table in the corresponding rows for each key and get the result.
mymat <- structure(c("chr5:12111", "chr5:12111", "chr5:12113", "chr5:12114", "chr5:12118", "0N", "0N", "1N", "0N", "0N", "00", "00", "00", "11", "10", "00", "00", "1N", "0N", "00"), .Dim = c(5L, 4L), .Dimnames = list( c("34", "35", "36", "37", "38"), c("key", "AMLM12001KP", "AMAS-11.3-Diagnostic", "AMLM12014N-R"))) key.table<- structure(c("chr5:12111", "chr5:12111", "chr5:12113", "chr5:12114", "chr5:12118", "chr5:12122", "chr5:12123", "chr5:12123", "chr5:12125", "chr5:12127", "chr5:12129", "9920068", "9920069", "9920070", "9920071", "9920072", "9920073", "9920074", "9920075", "9920076", "9920077", "9920078"), .Dim = c(11L, 2L), .Dimnames = list(c("34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44"), c("key", "variantId")))
Result
key variantId matched.extract 34 "chr5:12111" "9920068" NA 35 "chr5:12111" "9920069" NA 36 "chr5:12113" "9920070" AMLM12001KP (1N),AMLM12014N-R (1N) 37 "chr5:12114" "9920071" AMAS-11.3-Diagnostic (11) 38 "chr5:12118" "9920072" AMAS-11.3-Diagnostic (10) 39 "chr5:12122" "9920073" NA 40 "chr5:12123" "9920074" NA 41 "chr5:12123" "9920075" NA 42 "chr5:12125" "9920076" NA 43 "chr5:12127" "9920077" NA 44 "chr5:12129" "9920078" NA