[R] missing values
Ulrich Leopold
uleopold at science.uva.nl
Thu Jun 27 12:18:40 CEST 2002
>>gsum <- function(v1, v2){
>
> + cond <- is.na(v1)
> + res1 <- tapply(v1[!cond], v2[!cond], function(x) sum(x[!is.na(x)]))
> + res2 <- tapply(v1, v2, function(x) sum(is.na(x)))
> + dat <- as.data.frame(rbind(table(v2), res1, res2))
> + dimnames(dat)[[1]] <- c("Freq", "Sum", "Missing")
> + cat("Missing in", deparse(substitute(v1)), ":", sum(cond), "\n")
> + dat
> + }
This works in the same way as before... NAs will be zeros.
I think it is rather a problem of sum. If I have only NAs sum returns 0. So
maybe sum starts as initial value at 0 and then adds the following values.
Could this be the reason? If yes. Can I tell sum:
do not sum if there is a missing value? na.rm, is.na, na.omit do not work
Regards, 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list