匹配矩阵
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
posted on 2023-04-04 20:28 Stellaself 阅读(65) 评论(0) 编辑 收藏 举报