integerOrNumeric {ClassifyR} | R Documentation |
Allows the same S4 subsetting function to be specified for object[i]
and
object[i:j]
, where i
and j
are integers.
Dario Strbenac
setClass("Container", representation(scores = "numeric")) setMethod("[", c("Container", "integerOrNumeric", "missing", "ANY"), function(x, i, j, ..., drop = TRUE) { new("Container", scores = x@scores[i]) }) dataset <- new("Container", scores = 1:10) dataset[1] # 1 is numeric. dataset[4:6] # 4:6 is a sequence of integers.