码迷,mamicode.com
首页 > 编程语言 > 详细

R语言 union、setdiff、insect

时间:2018-04-29 12:04:53      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:net   bcd   https   union   strong   tps   s/4   .net   log   

union

求两个向量的并集
集合可以是任何数值类型

union(x=1:3, y=2:5)
[1] 1 2 3 4 5

union(x=c("abc", "12"), y=c("bcd", "efg"))
[1] "abc" "12"  "bcd" "efg"

setdiff

求向量x与向量y中不同的元素(只取x中不同的元素)
setdiff(x, y)

setdiff(x=1:4, y=2:3)
[1] 1 4


intersect

两个向量的交集

intersect(x=c(1:5, NA), y = c(2:5, NA))
[1]  2  3  4  5 NA

# 两个字符串向量的交集只有一个元素 "abc"
intersect(x=c("abc", "bcd"), y = c("abc", 12, "apple"))
[1] "abc"

 

ref:

https://blog.csdn.net/u011402596/article/details/44281271

R语言 union、setdiff、insect

标签:net   bcd   https   union   strong   tps   s/4   .net   log   

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

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