Andre_k
Andre_k

Reputation: 1728

Unique command in r giving strange result

This is my vector

aqq=c("35.7 Lac", "35.7 Lac", "1.65 Cr" , "1.65 Cr" , "2.03 Cr" , "2.03 Cr" , "1.76 Cr" , "1.76 Cr", 
 "1.67 Cr",  "1.67 Cr",  "2.26 Cr" , "2.26 Cr" , "2.24 Cr" , "2.24 Cr" , "1.98 Cr",  "1.98 Cr", 
 "3 Cr",     "3 Cr" ,    "2.34 Cr" , "2.34 Cr" , "27.2 Lac", "27.2 Lac", "36.5 Lac", "36.5 Lac",
 "55.7 Lac", "55.7 Lac", "1.89 Cr" , "1.89 Cr" , "78.7 Lac" ,"78.7 Lac" ,"1.71 Cr" , "1.71 Cr", 
 "2.31 Cr",  "2.31 Cr" , "1.58 Cr" , "1.58 Cr" , "2.09 Cr",  "2.09 Cr" , "1.92 Cr" , "1.92 Cr", 
 "70 Lac"  , "70 Lac" ,  "97 Lac" ,  "97 Lac" ,  "61 Lac"  , "61 Lac" ,  "90 Lac" ,  "90 Lac",  
 "80 Lac"   ,"80 Lac" ,  "57 Lac" ,  "57 Lac" ,  "2.34 Cr",  "2.34 Cr",  "3.20 Cr",  "3.20 Cr", 
 "2.38 Cr",  "2.38 Cr",  "2.86 Cr" , "2.86 Cr" , "1.35 Cr" , "1.35 Cr")

I'm trying to find unique elements from this vector and then separate the amount and unit of it and store them in separate vector, but when I do

 unique(aqq) 

it gives only 30 distinct elements,instead it should give me 31, as there are total 62 elements(31 duplicate) in it.

o/p

"35.7 Lac" "1.65 Cr"  "2.03 Cr"  "1.76 Cr"  "1.67 Cr"  "2.26 Cr"  "2.24 Cr"  "1.98 Cr" 
  "3 Cr"     "2.34 Cr"  "27.2 Lac" "36.5 Lac" "55.7 Lac" "1.89 Cr"  "78.7 Lac" "1.71 Cr" 
 "2.31 Cr"  "1.58 Cr"  "2.09 Cr"  "1.92 Cr"  "70 Lac"   "97 Lac"   "61 Lac"   "90 Lac"  
 "80 Lac"   "57 Lac"   "3.20 Cr"  "2.38 Cr"  "2.86 Cr"  "1.35 Cr"

as you can see "2.34 Cr" is the element which is missing. why is it so? can any one help me with this.

Upvotes: 0

Views: 60

Answers (1)

Łukasz Deryło
Łukasz Deryło

Reputation: 1860

"2.34 Cr" is there: it's the second entry in second row

And it appears four times in aqq

> which(aqq=="2.34 Cr")
[1] 19 20 53 54

Which is why you have only 30 entries in unique(aqq)

Upvotes: 2

Related Questions