[R] missing values
Bill.Venables@cmis.csiro.au
Bill.Venables at cmis.csiro.au
Thu Jun 27 10:23:58 CEST 2002
> -----Original Message-----
> From: Ulrich Leopold [mailto:uleopold at science.uva.nl]
> Sent: Thursday, June 27, 2002 4:56 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] missing values
>
> Dear list,
>
> how can I exclude the missing values in the following example:
>
> tapply(lsk0t50$Pox2, lsk0t50$ProfN, sum)
>
> I tried:
>
> tapply(lsk0t50$Pox2, lsk0t50$ProfN, sum, Fun=is.na(lsk0t50$Pox2))
[WNV] If you use
tapply(thevariable, thefactor, sum, na.rm = TRUE)
you will *almost* get what you want.
> But it returns a lot of missing values in the result. Instead the missing
> values in the variable should not be taken into account. So that I get
> only
> a NA as result if there are only NAs for the corresponding factor.
[WNV] If all values in the variable are missing and you remove them
you get an empty sum, which is 0, not NA. So if you want this non-standard
definition of the result of an empty sum you have to say so explicitly. One
way to do it is as follows:
mySpecialSum <- function(x) if(all(is.na(x)) || length(x) == 0) NA
else sum(x, na.rm = TRUE)
lapply(thevariable, thefactor, mySpecialSum)
If you have missings in the factor (as you seem to say above) you
are in a spot of bother.
Bill Venables.
ny idea how this can be achieved?
> Thanks,
> Ulrich
> --
> __________________________________________________
>
> Ulrich Leopold MSc.
>
> Department of Physical Geography
> Institute for Biodiversity and Ecosystem Dynamics
> Faculty of Science
> University of Amsterdam
> Nieuwe Achtergracht 166
> NL-1018WV Amsterdam
>
> Phone: +31-(0)20-525-7456 (7451 Secretary)
> Fax: +31-(0)20-525-7431
> Email: uleopold at science.uva.nl
> http://www.frw.uva.nl/soil/Welcome.html
>
> Check us also out at:
> Netherlands Centre for Geo-ecological Research
> http://www.frw.uva.nl/icg
>
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-
> r-help mailing list -- Read
> http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list