SCM

SCM Repository

[matrix] Diff of /pkg/R/Matrix.R
ViewVC logotype

Diff of /pkg/R/Matrix.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2552, Thu Jun 24 19:36:40 2010 UTC revision 2553, Sat Jun 26 06:50:03 2010 UTC
# Line 50  Line 50 
50  setMethod("as.logical", signature(x = "Matrix"),  setMethod("as.logical", signature(x = "Matrix"),
51            function(x, ...) as.logical(as.vector(x)))            function(x, ...) as.logical(as.vector(x)))
52    
53    setMethod("mean", signature(x = "sparseMatrix"),
54              function(x, ...) mean(as(x,"sparseVector"), ...))
55    setMethod("mean", signature(x = "sparseVector"),
56              function(x, trim = 0, na.rm = FALSE, ...)
57          {
58              if (na.rm) # remove NAs such that new length() is ok
59                  x <- x[!is.na(x)] # remains sparse!
60              if(is0(trim)) sum(x) / length(x)
61              else {
62                  ## fast trimmed mean for sparseVector:
63                  ## ---> we'd need fast & sparse  sort(<sparseV>).
64                  ##      Normally this means to define a xtfrm() method;
65                  ##      however, that plus  x[order(x, ..)]  will NOT be sparse
66                  ## TODO: sortSparseVector(.)
67                  warning("trimmed mean of 'sparseVector' -- suboptimally using as.numeric(.)")
68                  mean(as.numeric(x), trim=trim)
69              }
70          })
71    ## for the non-"sparseMatrix" ones:
72  setMethod("mean", signature(x = "Matrix"),  setMethod("mean", signature(x = "Matrix"),
73            function(x, trim = 0, ...) ## TODO: provide 'sparseMatrix method            function(x, trim = 0, na.rm = FALSE, ...)
74            if(is0(trim)) sum(x, ...) / length(x)        {
75            else mean(as.numeric(x), ...))            if (na.rm)
76                  x <- x[!is.na(x)]
77              if(is0(trim)) sum(x) / length(x)
78              else mean(as.numeric(x), trim=trim)
79          })
80    
81    
82  setMethod("cov2cor", signature(V = "Matrix"),  setMethod("cov2cor", signature(V = "Matrix"),
83            function(V) { ## was as(cov2cor(as(V, "matrix")), "dpoMatrix"))            function(V) { ## was as(cov2cor(as(V, "matrix")), "dpoMatrix"))

Legend:
Removed from v.2552  
changed lines
  Added in v.2553

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge