[R] remove duplicated row according to NA condition

jeff6868 geoffrey_klein at etu.u-bourgogne.fr
Wed May 28 14:35:37 CEST 2014


Hi everybody,

I have a little problem in my R-code which seems be easy to solve, but I
wasn't able to find the solution by myself for the moment.

Here's an example of the form of my data:

data <-
data.frame(col1=c("a","a","b","b"),col2=c(1,1,2,2),col3=c(NA,"ST001","ST002",NA))

I would like to remove duplicated data based on the first two columns
(col1,col2), but in both cases here, I would like to remove the duplicated
row which is equal to NA in col3.

Here's the data.frame I would like to obtain:

data2 <- data.frame(col1=c("a","b"),col2=c(1,2),col3=c("ST001","ST002"))

I've been trying to mix duplicated() with is.na() but it doesn't work yet.

Can someone tell me the best and easiest way to do this?

Thanks a lot!







--
View this message in context: http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list