Hi R-helper!
I have problem with setMethods for "[". Here is example :
setClass("myClass", representation(ID.r = "numeric", ID.c = "character", DAT =
"matrix"))
to.myClass <- function(ID.r, ID.c, DAT) {
out <- new("myClass", ID.r = ID.r, ID.c = ID.c, DAT = DAT)
return(out)
}
setMethod("[", "myClass", function(x, i, j, drop) {
[email protected] <- [email protected][i]
[email protected] <- [email protected][j]
out.0 <- x@DAT[i,j]
out.1 <- to.myClass([email protected], [email protected], as.matrix(out.0))
return(out.1)
})
a <- to.myClass(seq(1,25), c("A","A","B","B"), matrix(rnorm(100), nrow = 25))
a
a[1:20, ] #works
a[, 1:3] #works
a[1:10, 1:3] #works
a[, "A"] #not works
What is solution to write "[" methods for extraction by names of Slot "ID.c"
Thanks all. OV
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.