1

This is a follow-up question to a previous post.

I need to write an initialize() method for a S4 class (named Band) that expects a matrix and a value for k. It should be defined as a function with formal arguments (x, k), and should put the lower triangular elements of X into the object.

Any suggestions appreciated.

Community
  • 1
  • 1
user635034
  • 43
  • 4
  • 4
    My suggestion is to read the manual and/or some of the fine tutorials available on [CRAN](http://cran.r-project.org). [This introduction to s4](http://cran.r-project.org/doc/contrib/Genolini-S4tutorialV0-5en.pdf) is probably a good place to start. – Ista Mar 05 '11 at 02:43
  • 3
    `initialize` methods are pretty tricky; maybe you really want to write a constructor `Band <- function(x, k) { <...> }` that calls `new("Band", slotA=<...>, slotB=<...>)` or perhaps a `coerce` method using `setAs`. – Martin Morgan Mar 05 '11 at 16:45
  • 2
    See also : http://stackoverflow.com/questions/4143611/sources-on-s4-objects-in-r – Joris Meys Apr 06 '11 at 09:39

1 Answers1

1

The Matrix package has many examples of matrix-related S4 classes and methods:

http://cran.r-project.org/web/packages/Matrix/

Download the source and check it out.

Paul 'Joey' McMurdie
  • 7,295
  • 5
  • 37
  • 41