Rでは、新しいクラスに演算子のオーバーロード(、、、など)を実装する方法+
は-
? で、動物園ライブラリのソース コードを確認しました。次のコードは機能しますか?*
./
ops.R
Ops.zoo <- function (e1, e2)
{
e <- if (missing(e2)) {
NextMethod(.Generic)
}
else if (any(nchar(.Method) == 0)) {
NextMethod(.Generic)
}
else {
merge(e1, e2, all = FALSE, retclass = NULL)
NextMethod(.Generic)
}
out <- if (is.null(attr(e, "index")))
zoo(e, index(e1), attr(e1, "frequency"))
else
e
# the next statement is a workaround for a bu g in R
structure(out, class = class(out))
}
私はmerge(e1,e2,..)
ブロックで迷っています。でテストしました
e1 <- zoo(rnorm(5), as.Date(paste(2003, 02, c(1, 3, 7, 9, 14), sep = "-")))
e2 <- e1
test <- merge(e1, e2, all = FALSE, retclass = NULL)
test
しかしそれではNULL
。仕組みはe <- {test; NextMethod(.Generic)}
?