a <- matrix(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15),nrow=3,ncol=5) c <- matrix(c(2,3,3,3,3,4,4,4,4,8,8,8),nrow=3,ncol=4) rownames(a)<-c("aa","cc","kk") rownames(c)<-c("dd","cc","ee") > a [,1] [,2] [,3] [,4] [,5] aa 1 4 7 10 13 cc 2 5 8 11 14 kk 3 6 9 12 15 > c [,1] [,2] [,3] [,4] dd 2 3 4 8 cc 3 3 4 8 ee 3 4 4 8 > rownames(c) [1] "dd" "cc" "ee" > rownames(c) %in% rownames(a) [1] FALSE TRUE FALSE > which(rownames(c) %in% rownames(a)) [1] 2 > a[which(rownames(c) %in% rownames(a)),] [1] 2 5 8 11 14 > c[which(rownames(c) %in% rownames(a)),] [1] 3 3 4 8
标签:匹配,14,cc,dd,矩阵,FALSE,rownames,in% From: https://www.cnblogs.com/stelladi/p/17287819.html