[R] Indexing with NA as FALSE??

Richard A. O'Keefe ok at cs.otago.ac.nz
Mon Jul 14 00:53:11 CEST 2003


	> Also, as an extra, it would be very useful if, for instance,
	> t[u==NA] --> 2 4 6 8
	> (I realise that working round this is less cumbersome, but even so).
	
What's wrong with writing t[is.na(u)]?

Or you could define
    eq <- function(x,y) {
	(is.na(x) & is.na(y)) | (!is.na(x) & !is.na(y) & x == y)
    }
and use
    t[eq(u,NA)]




More information about the R-help mailing list