I have the following code
obj <- list(list(a=4,f=5,g=5),list(a=44,f=54,g=54))
class(obj) <- "mysubclass"
class(obj[1])
class(obj[2])
class(obj[1:2])
class(obj)
resulting in:
> class(obj[1])
[1] "list"
> class(obj[2])
[1] "list"
> class(obj[1:2])
[1] "list"
> class(obj)
[1] "mysubclass"
What would be proper solution to not lose the class by subsetting? FOr example, class(obj[1:2])
results in mysubclass
and still behaves as a list.