The class "ecdf" inherits from the class "stepfun". If f
is such an empirical cumulative density function,
both is.stepfun(f)
and is(f,"stepfun")
are TRUE
, and as.stepfun(f)
doesn't do anything as expected.
But conversion of f
to "stepfun" by as(f,"stepfun")
is impossible because of the "metadata", even if strict
is FALSE
:
f <- ecdf(1:10)
class(f)
# [1] "ecdf" "stepfun" "function"
is.stepfun(f)
# [1] TRUE
is(f,"stepfun")
# [1] TRUE
identical(f,as.stepfun(f))
# [1] TRUE
g <- as(f,"stepfun",strict=FALSE)
# Error in as(f, "stepfun", strict = FALSE) :
# internal problem in as(): “ecdf” is(object, "stepfun") is TRUE, but the metadata asserts that the 'is' relation is FALSE
So how is is
related to as
and what is the meaning of the "metadata" here?
I may have found some relevant information. At this nabble archive
but it has two problems: 1) as() is an S4 method that does not always work (problem 2 not relevant)
Locally :-) this SO question has warnings about trying to use as()
So my suggestion would be to stick with as.stepfun(foo)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With