如何将矩阵更改为只有唯一数字的矩阵
我试过这个:
dataset <- as.matrix(iris[,1:4])
head(dataset)
Sepal.Length Sepal.Width Petal.Length Petal.Width
[1,] 5.1 3.5 1.4 0.2
[2,] 4.9 3.0 1.4 0.2
[3,] 4.7 3.2 1.3 0.2
[4,] 4.6 3.1 1.5 0.2
[5,] 5.0 3.6 1.4 0.2
[6,] 5.4 3.9 1.7 0.4
datasetUnique <- jitter(dataset,factor = 0.001)
head(datasetUnique)
Sepal.Length Sepal.Width Petal.Length Petal.Width
[1,] 5.100001 3.499998 1.399999 0.2000009
[2,] 4.900000 2.999999 1.399999 0.2000016
[3,] 4.700001 3.199999 1.300000 0.1999983
[4,] 4.600001 3.100002 1.500001 0.1999988
[5,] 4.999999 3.599999 1.399998 0.1999989
[6,] 5.399999 3.900000 1.699999 0.3999981
但这并不能使所有数字都独一无二。我如何做到这一点?