在R語言中,可以使用unique()函數來從數組中查找唯一值。示例如下:
unique()
# 創建一個包含重復元素的數組 arr <- c(1, 2, 3, 4, 1, 2, 5) # 使用unique()函數查找唯一值 unique_values <- unique(arr) print(unique_values)
運行上述代碼后,將輸出數組arr中的唯一值:
arr
[1] 1 2 3 4 5