2016-01-27 8 views
5

Il class "ecdf" eredita dalla classe "stepfun". Se f è una funzione di densità cumulativa empirica, eee as.stepfun(f) non fanno nulla come previsto. Ma la conversione di f a "stepfun" di as(f,"stepfun") è impossibile a causa della "metadati", anche se strict è FALSE:R: Come mai che "è" è VERO, ma "come" è impossibile?

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 

Così come è is legato alla as e qual è il significato della "metadati" Qui?

+0

intendevi 'is.stepfun (f)' subito dopo 'class (f)'? –

+0

Mi interessa - dove hai scavato il formato 'is (item, typedef)' al contrario del formato in tutte le pagine di aiuto 'is.typedef (item)'? Potresti anche voler provare 'methods (as)' e un paio di ricerche simili per vedere cosa sta succedendo con la classe 'stepfun' in particolare. –

+1

@Carl Witthoft: la ricerca di "R coercing" conduce alla [documentazione per il metodo 'as'] (https://stat.ethz.ch/R-manual/R-devel/library/methods/html/as. html). Vi è un collegamento ([setIs] (https://stat.ethz.ch/R-manual/R-devel/library/methods/html/is.html) alla [documentazione per il metodo 'is'] (https://stat.ethz.ch/R-manual/R-devel/library/methods/html/is.html). – mra68

risposta

2

Forse ho trovato alcune informazioni rilevanti. A this nabble archive

but it has two problems: 

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

Localmente :-) this SO question ha avvertimenti circa il tentativo di utilizzare as()

Quindi il mio suggerimento sarebbe quello di attaccare con as.stepfun(foo).

Problemi correlati