码迷,mamicode.com
首页 > 其他好文 > 详细

Match function in R

时间:2018-04-28 10:46:15      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:function   .com   nbsp   ogg   logger   match   log   str   lse   

 

Examples:
 
    
print(match(5, c(1,2,9,5,3,6,7,4,5)))
[1] 4
 
    
5 %in% c(1,2,9,5,3,6,7,4,5)
[1] TRUE
 
    
8 %in% c(1,2,9,5,3,6,7,4,5)
[1] FALSE
 
> v1 <- c("a1","b2","c1","d2")
> v2 <- c("g1","x2","d2","e2","f1","a1","c2","b2","a2")
> x <- match(v1,v2)
> x
[1] 6 8 NA 3
 
    
> v1 <- c("a1","b2","c1","d2")
> v2 <- c("g1","x2","d2","e2","f1","a1","c2","b2","a2")
> v1 %in% v2
[1] TRUE TRUE FALSE TRUE
 
    
> v1 <- c("a1","b2","c1","d2")
> v2 <- c("g1","x2","d2","e2","f1","a1","c2","b2","a2")
> x <- match(v1,v2, nomatch = 0)
> x
[1] 6 8 0 3
 
    
> v1 <- c("a1","b2","c1","d2")
> v2 <- c("g1","x2","d2","e2","f1","a1","c2","b2","a2")
> x <- match(v1,v2, nomatch = 0, incomparables = "a1")
> x
[1] 0 8 0 3

 

ref:

https://www.r-bloggers.com/match-function-in-r/

 

Match function in R

标签:function   .com   nbsp   ogg   logger   match   log   str   lse   

原文地址:https://www.cnblogs.com/emanlee/p/8965683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!