当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R语言 make.unique()用法及代码示例


R 语言中的 make.unique() 函数用于通过将序列号附加到重复项来返回具有唯一名称的向量元素。

用法: make.unique(names, sep)
参数: 
names: Character vector with duplicate names 
sep: Separator to be used 
 

范例1:

Python3


# R program to make unique vectors
  
# Calling make.unique() Function
make.unique(c("a", "a", "a"))
make.unique(c("a", "b", "c", "a"))
make.unique(c("1", "2", "3", "1", "2"))

输出:



[1] "a"   "a.1" "a.2"
[1] "a"   "b"   "c"   "a.1"
[1] "1"   "2"   "3"   "1.1" "2.1"

范例2:

Python3


# R program to make unique vectors
  
# Calling make.unique() Function
# with different separator values
make.unique(c("a", "a", "a"), sep = "_")
make.unique(c("a", "a", "a"), sep = "@")
make.unique(c("a", "a", "a"), sep = "$")

输出:

[1] "a"   "a_1" "a_2"
[1] "a"   "a@1" "a@2"
[1] "a"   "a$1" "a$2"

相关用法


注:本文由纯净天空筛选整理自nidhi_biet大神的英文原创作品 Make Elements of a Vector Unique in R Programming – make.unique() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。