SCM

SCM Repository

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

Diff of /pkg/R/sparseMatrix.R

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

revision 1910, Mon Jun 18 16:34:38 2007 UTC revision 1911, Tue Jun 19 16:16:58 2007 UTC
# Line 424  Line 424 
424            })            })
425    
426    
 ## .as.dgT.Fun  
 setMethod("colSums",  signature(x = "sparseMatrix"), .as.dgT.Fun)  
 setMethod("colMeans", signature(x = "sparseMatrix"), .as.dgT.Fun)  
 ## .as.dgC.Fun  
 setMethod("rowSums", signature(x = "sparseMatrix"), .as.dgC.Fun)  
 setMethod("rowMeans", signature(x = "sparseMatrix"),.as.dgC.Fun)  
   
427  lm.fit.sparse <-  lm.fit.sparse <-
428  function(x, y, offset = NULL, method = c("qr", "cholesky"),  function(x, y, offset = NULL, method = c("qr", "cholesky"),
429           tol = 1e-7, singular.ok = TRUE, transpose = FALSE, ...)           tol = 1e-7, singular.ok = TRUE, transpose = FALSE, ...)
# Line 452  Line 445 
445      ans      ans
446  }  }
447    
448  setAs("factor", "sparseMatrix",  fac2sparse <- function(from, to = c("d","i","l","n","z"))
       function(from)  
449    {    {
450        fact <- as.factor(from)[, drop = TRUE]      ## factor(-like) --> sparseMatrix {also works for integer, character}
451        levs <- levels(fact)      levs <- levels(fact <- factor(from)) # drop unused levels
452        n <- length(fact)        n <- length(fact)
453        new("dgCMatrix", p = 0:n, i = as.integer(fact) - 1L, # 0-based      to <- match.arg(to)
454            x = rep.int(1, n), Dim = c(length(levs), n),      res <- new(paste(to, "gCMatrix", sep=''))
455            Dimnames = list(levels(fact), NULL))      res@i <- as.integer(fact) - 1L # 0-based
456        res@p <- 0:n
457        res@Dim <- c(length(levs), n)
458        res@Dimnames <- list(levs, NULL)
459        if(to != "n")
460            res@x <- rep.int(switch(to,
461                                    "d" = 1., "i" = 1L, "l" = TRUE, "z" = 1+0i),
462                             n)
463        res
464    }    }
       )  
465    
466    setAs("factor", "sparseMatrix", function(from) fac2sparse(from, to = "d"))

Legend:
Removed from v.1910  
changed lines
  Added in v.1911

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