Skip to content
Prev 326392 / 398502 Next

Unique in discerning missing values NA

Yes thanks, this is what I ended up doing, but I though there would be a 'internal' way to disregard NAs in unique.
Thanks for the tip on dput

-----Original Message-----
From: Rui Barradas [mailto:ruipbarradas at sapo.pt] 
Sent: 05 July 2013 11:39
To: Pancho Mulongeni
Cc: r-help at r-project.org
Subject: Re: [R] Unique in discerning missing values NA

Hello,

Your data example is difficult to read into an R session. Next time, post the output of ?dput. Like this:

dput(menPatients[1:40, 1])  # post the output of this


The help page for unique says that "Missing values are regarded as equal"  so you should expect one NA to still be present in the final result.
If you want to remove NAs, use ?is.na. With fake data,

x1 <- c(1:3, NA, 4, NA, 2:9)
x2 <- unique(x1)
x3 <- x2[!is.na(x2)]
x3


Hope this helps,

Rui Barradas


Em 05-07-2013 10:28, Pancho Mulongeni escreveu: