set(sets)
set()所属R语言包:sets
Sets
集
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Creation and manipulation of sets.
创建和操作的集合。
用法----------Usage----------
set(...)
as.set(x)
make_set_with_order(x)
is.set(x)
set_is_empty(x)
set_is_subset(x, y)
set_is_proper_subset(x, y)
set_is_equal(x, y)
set_contains_element(x, e)
set_union(...)
set_intersection(...)
set_symdiff(...)
set_complement(x, y)
set_cardinality(x)
## S3 method for class 'set'
length(x)
set_power(x)
set_cartesian(...)
set_combn(x, m)
参数----------Arguments----------
参数:x
For as.set() and is.set(): an R object. A set object otherwise.
对于as.set()和is.set():R对象。否则一组对象。
参数:y
A set object.
一组对象。
参数:e
An R object.
R对象。
参数:m
Number of elements to choose.
选择的元素的数量。
参数:...
For set(): R objects, and set objects otherwise.
set():R对象,并集对象,否则。
Details
详细信息----------Details----------
These functions represent basic infrastructure for handling sets of general (R) objects. The set_is_<VAR>foo</VAR>() predicates are vectorized. In addition to the methods defined, one can use the following operators: | for the union, - for the difference (or complement), & for the intersection, %D% for the symmetric difference, * and ^<VAR>n</VAR> for the (n-fold) cartesian product, 2^ for the power set, %e% for the element-of predicate, < and <= for the (proper) subset predicate, > and >= for the (proper) superset predicate, and == and != for (in)equality. The length method for sets gives the cardinality. set_combn returns the set of all subsets of specified length. The Summary methods do also work if defined for the set elements. The mean and median methods try to convert the object to a numeric vector before calling the default methods.
这些功能一般(R)对象处理组代表的基础设施。 set_is_<VAR>foo</VAR>()谓词的量化。除了定义的方法,可以使用下列运算符:|工会,-的差异(或补体),&的交集,%D%的对称差,*和^<VAR>n</VAR>(n倍)笛卡尔积,2^发电机组,%e%元素的谓词,<和<=(正确)的子集的谓词,>和>=(正确的)超谓词,和==和<X >(不)平等。 !=方法集给出的基数。 length返回指定长度的所有子集的集合。 set_combn方法工作,如果定义的集合元素。 Summary和mean方法试图将对象转换为一个数值向量,然后再调用默认的方法。
Because set elements are unordered, it is not allowed to use positional indexing. However, it is possible to do indexing using element labels or simply the elements themselves (useful, e.g., for subassignment). In addition, it is possible to iterate over all elements using for and lapply/sapply.
由于集合的元素是无序的,它是不允许使用位置索引。但是,它是能够使用元素标签或简单的元素本身(有用的,例如,用于subassignment)做索引。此外,它是可以重复使用for和lapply/sapply的所有元素。
Note that converting objects to sets may change the internal order of the elements, so that iterating over the original data might give different results than iterating over the corresponding set. The permutation can be obtained using the generic function make_set_with_order, returning both the set and the ordering. as.set simply calls make_set_with_order internally and strips the order information, so user-defined methods for coercion have to be provided for the latter and not for as.set.
需要注意的是将对象转换为组可能会改变内部的元素顺序,使迭代的原始数据,可能会得到不同的结果比相应的一组迭代。可以使用通用的函数make_set_with_order,返回两个集和排序的排列。 as.set只是简单地调用make_set_with_order内部和钢带的订单信息,所以用户自定义的方法强迫后者必须提供,而不是为as.set。
Note that set_union, set_intersection, and set_symdiff accept any number of arguments. The n-ary symmetric difference of sets contains just elements which are in an odd number of the sets.
请注意这set_union,set_intersection,set_symdiff接受任意数量的参数。 n进制对称差集只包含在奇数的集的元素。
set_contains_element is vectorized in e, that is, if e is an atomic vector or list, the is-element operation is performed element-wise, and a logical vector returned. Note that, however, objects of class tuple are taken as atomic objects to correctly handle sets of tuples.
set_contains_element矢量化e,也就是说,如果e是一个的原子向量或列表,是件工作是明智的元素,并返回一个逻辑向量。请注意,但是,对象的类tuple原子对象正确处理元组套。
值----------Value----------
For the predicate functions, a logical. For make_set_with_order, a list with two components "set" and "order". For set_cardinality and the length method, an integer value. For all others, a set.
对于谓词函数的逻辑。对于make_set_with_order,一个列表两部分组成"set"和"order"。 set_cardinality和长度的方法,一个整型值。对于所有其他的一组。
参考文献----------References----------
Generalized and customizable sets in R, Journal of Statistical Software 31(2), 1–27. http://www.jstatsoft.org/v31/i02/
参见----------See Also----------
set_outer, gset for generalized sets, and tuple for tuples (“vectors”).
set_outer,gset广义集,和tuple的元组(“向量”)。
实例----------Examples----------
## constructor[#构造]
s <- set(1L, 2L, 3L)
s
## named elements[#命名的元素]
snamed <- set(one = 1, 2, three = 3)
snamed
## indexing by label[#索引标签]
snamed[["one"]]
## subassignment[#subassignment]
snamed[c(2,3)] <- c("a","b")
snamed
## a more complex set[#一组更复杂]
set(c, "test", list(1, 2, 3))
## converter[#转换器]
s2 <- as.set(2:5)
s2
## converter with order[#转炉与秩序]
make_set_with_order(5:1)
## set of sets[#设定集]
set(set(), set(1))
## cartesian product[#笛卡尔积]
s * s2
s * s
s ^ 2 # same as above[与上述相同]
s ^ 3
## power set[#发电机组]
2 ^ s
## tuples[#元组]
s3 <- set(tuple(1,2,3), tuple(2,3,4))
s3
## Predicates:[#谓词:]
## element[#元素]
1:2 %e% s
tuple(1,2,3) %e% s3
## subset[#子集]
s <= s2
s2 >= s # same[同]
## proper subset[#适当的子集]
s < s
## complement, union, intersection, symmetric difference:[#补充,并集,交集,对称差:]
s - 1L
s + set("a") # or use: s | set("a")[或使用:S组(“A”)]
s & s
s %D% s2
set(1,2,3) - set(1,2)
set_intersection(set(1,2,3), set(2,3,4), set(3,4,5))
set_union(set(1,2,3), set(2,3,4), set(3,4,5))
set_symdiff(set(1,2,3), set(2,3,4), set(3,4,5))
## subsets:[#子集:]
set_combn(as.set(1:3),2)
## iterators:[#迭代器:]
sapply(s, sqrt)
for (i in s) print(i)
## Summary methods[#摘要方法]
sum(s)
range(s)
## mean / median[#平均数/中位数]
mean(s)
median(s)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|