[R] HI

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Tue Sep 16 16:20:16 CEST 2008


> > Does anyone know an easy way to convert all the zero values in a 
> imported csv table into NA's
> 
> Depends on the data structure you gave your imported table. In a 
> single numeric vector (named, say, vec), the syntax is
> 
> is.na(vec[vec==0]) <- TRUE

That throws errors for me.  An alternative is 
vec[vec==0] <- NA

This also works for data frames, e.g.
df <- data.frame(a=c(1,2,3,0,3,4,0,5,2), b=c(1,0,0,1,1,0,1,1,0))
df[df==0] <- NA

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-help mailing list