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"
相關用法
- R語言 as.vector()用法及代碼示例
- R語言 is.vector()用法及代碼示例
- R語言 topo.colors()用法及代碼示例
- R語言 cm.colors()用法及代碼示例
- R語言 terrain.colors()用法及代碼示例
- R語言 replace()用法及代碼示例
- R語言 seq()用法及代碼示例
- R語言 diff()用法及代碼示例
- R語言 median()用法及代碼示例
- R語言 sign()用法及代碼示例
- R語言 char.expand()用法及代碼示例
- R語言 unique()用法及代碼示例
- R語言 append()用法及代碼示例
- R語言 rep()用法及代碼示例
- R語言 charmatch()用法及代碼示例
- R語言 substring()用法及代碼示例
- R語言 str_detect()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi_biet大神的英文原創作品 Make Elements of a Vector Unique in R Programming – make.unique() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。