[R] a method to trim composite objects?

Francois.Bastardie at ifremer.fr Francois.Bastardie at ifremer.fr
Fri Jun 16 17:50:18 CEST 2006


dear R users,

please, consider the following code you may run:

setClass("my.class1",

      representation(
          my.list        = "list",
          my.array1      = "array"),
      prototype=prototype(
          my.list        =list(),
          my.array1      =array(0,c(3,3,3))
                          ))



#------------------

setClass("my.class2",
      representation(
          my.array2        = "array",
          my.array3        = "array"),
      prototype=prototype(
          my.array2        =array(0,c(3,3,3)),
          my.array3        =array(0,c(3,3,3))
                           ))



#------------------

x <- new("my.class1")
x at my.list[[1]] <- new("my.class2")
x at my.list[[2]] <- new("my.class2")


Is there any method in R to trim dimensions of all the component arrays 
(my.array1, my.array2, my.array3, etc.) in one time inside all the 
hierarchical level of the composite object I named 'x'?

in other words, if I want to keep only the 2nd dimension, I have to do:
x at my.array1[,2,]
x at my.list[[1]]@my.array2[,2,]
x at my.list[[1]]@my.array3[,2,]
x at my.list[[2]]@my.array2[,2,]
x at my.list[[2]]@my.array3[,2,]
etc.

thank you


-- 
--------------------------------------------------------
François Bastardie

French Research Institute for the Development of the Sea (IFREMER)
Ecologie et Modèles pour l'Halieutique
Rue de l'Ile d'Yeu
BP 21105
44311 NANTES Cedex 03 - France
Tél : 02 40 37 41 64
Fax : 02 40 37 40 75
E-mail : francois.bastardie at ifremer.fr



More information about the R-help mailing list