Reputation: 1029
If I have this data:
library(trend)
v <- runif(100) * 1:100
func <- function(x,na.rm=T) { unlist(sens.slope(x)) }
func(v,na.rm=T)
everything went right and no problem. But in my real data there is NA.
v[1]=NA
func(v,na.rm=T)
I got this error: Error in na.fail.default(x) : missing values in object
Upvotes: 1
Views: 883
Reputation: 486
Set v <- v[!is.na(v)]
first (before supplying v
to func
) and it should run fine.
Or else adjust your function, in which case the above is unnecessary:
func <- function(x,na.rm=T) {
if(sum(is.na(x)) == length(x)) return(NA)
if(na.rm) x <- x[!is.na(x)]
unlist(sens.slope(x))
}
Upvotes: 1