Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

If while you are developing or modifying a function (server-side or client-side) the function appears to run OK but there are unexpected missings/NAs in the output make sure you that the function is not configured correctly to deal with missing values.

Example of problem
#If data (e.g. X) contain missing values (typically, NAs)
mean(X) #will return NA
mean(X,na.rm=TRUE) #will omit NAs and then do calculation correctly
 
#It is important to remember that if you are developing a function like tapply or lapply that
#itself calls functions like mean(), those will also return NAs if you don't make sure that
#that tapply/lapply calls the function with na.rm included.
 
#For example, see meanByGroupDS. The line:
FUN <- function (x) {UseMethod("mean")}
 
#returns NAs when lapply calls FUN
#So you must use:
FUN <- function(x) {mean(x,na.rm=TRUE)}
  • No labels