简体   繁体   中英

Matching the values of two vectors

I have the data frame:

AA<-c(4,1,5,3,2,13,17,16,14,15,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA)

BB<-c(3,15,4,2,13,19,20,14,7,12,8,18,11,5,16,17,9,6,10,1)

CC<-c(118,106,115,120,105,111,104,101,102,110,119,108,113,109,114,116,103,107,112,117)

DD<-data.frame(AA,BB,CC)

How can I create a vector containing the values of CC that correspond the numbers of BB matching the numbers of AA ?

I want the EE to look like this: 115,117,109,118,120,105,116,114,101,106 , (I don't care what happens after row 10)

您可以使用匹配功能在BB中查找AA的位置,然后从CC中选择这些位置。

DD$CC[match(DD$AA, DD$BB)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM