The function unique in R is not working for real numbers

515 Views Asked by At

I have a data frame that looks like following:

> con.hull.mod
           x         y
1  2.5558145 4.1739617
2  5.0180096 5.4267733
3  5.0180096 5.4267733
4  6.2151346 6.0358932
5  6.3582981 6.1087375
6  6.3582053 5.8702711
7  6.3574907 4.0355980
8  6.3574907 4.0355980
9  6.3565247 1.5554874
10 6.3560029 0.2155812
11 4.0490978 0.6009829
12 0.9284811 3.3459437

Clearly row numbers 7 and 8 are identical. I am using the function unique() to get the non-repeating rows. But it seems that the function fails for real numbers (or am I mistaken in some way?).

> unique(con.hull.mod)
           x         y
1  2.5558145 4.1739617
2  5.0180096 5.4267733
3  5.0180096 5.4267733
4  6.2151346 6.0358932
5  6.3582981 6.1087375
6  6.3582053 5.8702711
7  6.3574907 4.0355980
8  6.3574907 4.0355980
9  6.3565247 1.5554874
10 6.3560029 0.2155812
11 4.0490978 0.6009829
12 0.9284811 3.3459437

How to avoid this problem? Thanks in advance for your help :)

1

There are 1 best solutions below

0
Mohamed Desouky On

unique works with no problem

unique(con.hull.mod)

  • output
           x         y
1  2.5558145 4.1739617
2  5.0180096 5.4267733
4  6.2151346 6.0358932
5  6.3582981 6.1087375
6  6.3582053 5.8702711
7  6.3574907 4.0355980
9  6.3565247 1.5554874
10 6.3560029 0.2155812
11 4.0490978 0.6009829
12 0.9284811 3.3459437
  • data
con.hull.mod <- structure(list(x = c(2.5558145, 5.0180096, 5.0180096, 6.2151346, 
6.3582981, 6.3582053, 6.3574907, 6.3574907, 6.3565247, 6.3560029, 
4.0490978, 0.9284811), y = c(4.1739617, 5.4267733, 5.4267733, 
6.0358932, 6.1087375, 5.8702711, 4.035598, 4.035598, 1.5554874, 
0.2155812, 0.6009829, 3.3459437)), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"))