2016-01-27 10 views
5

Obiekt class "ecdf" dziedziczy po klasie "stepfun". Jeśli f jest taką empiryczną skumulowaną funkcją gęstości, zarówno is.stepfun(f), jak i is(f,"stepfun")TRUE, a as.stepfun(f) nie robi niczego zgodnie z oczekiwaniami. Ale konwersja f do „stepfun” przez as(f,"stepfun") jest niemożliwe ze względu na „metadane”, nawet jeśli strict jest FALSE:R: Dlaczego to "jest" jest PRAWDĄ, ale "jak" jest niemożliwe?

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 

Więc jak jest is związane as i jaki jest sens „metadane” tutaj?

+0

miałeś na myśli 'is.stepfun (f)' zaraz po 'class (f)'? –

+0

Jestem zainteresowany - gdzie wykopałeś format 'is (item, typedef)' w przeciwieństwie do formatu na wszystkich stronach pomocy 'is.typedef (item)'? Możesz także spróbować "metod (as)" i kilku podobnych badań, aby zobaczyć, co się dzieje w szczególności z klasą "stepfun". –

+1

@Carl Witthoft: Wyszukiwanie "R wymuszenie" prowadzi do [dokumentacji metody "as"] (https://stat.ethz.ch/R-manual/R-devel/library/methods/html/as. html). W tym miejscu znajduje się link ([setIs] (https://stat.ethz.ch/R-manual/R-devel/library/methods/html/is.html)) do [dokumentacji metody 'is'] (https://stat.ethz.ch/R-manual/R-devel/library/methods/html/is.html). – mra68

Odpowiedz

2

Mogę znaleźć kilka istotnych informacji. Na this nabble archive

but it has two problems: 

1) as() is an S4 method that does not always work 
(problem 2 not relevant) 

Lokalnie :-) this SO question ma ostrzeżenia o próbie użycia as()

Więc moja propozycja będzie trzymać as.stepfun(foo).

Powiązane problemy