SCM

SCM Repository

[rmetrics] Annotation of /pkg/timeSeries/R/base-rowCumsums.R
ViewVC logotype

Annotation of /pkg/timeSeries/R/base-rowCumsums.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4903 - (view) (download)

1 : wuertz 4158 #
2 :     # This program is free software; you can redistribute it and/or modify
3 :     # it under the terms of the GNU General Public License as published by
4 :     # the Free Software Foundation; either version 2 of the License, or
5 :     # (at your option) any later version.
6 :     #
7 :     # This program is distributed in the hope that it will be useful,
8 :     # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 :     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 :     # GNU General Public License for more details.
11 :     #
12 :     # A copy of the GNU General Public License is available at
13 :     # ../../COPYING
14 :    
15 :    
16 :     ################################################################################
17 :     # FUNCTION: DESCRIPTION:
18 : chalabi 4903 # rowCumsums,ANY Computes cumulated sums by row
19 : wuertz 4158 # rowCumsums,timeSeries Computes cumulated sums by row for timeSeries
20 :     ################################################################################
21 :    
22 : chalabi 4903 setMethod("rowCumsums", "ANY", function(x, na.rm = FALSE, ...)
23 :     {
24 :     # Transform:
25 :     if (!inherits(x, 'matrix'))
26 :     x <- as(x, "matrix")
27 : wuertz 4158
28 : chalabi 4903 if (na.rm)
29 :     x <- na.omit(x)
30 : wuertz 4158
31 : chalabi 4903 ans <- apply(x, 1, cumsum, ...)
32 : wuertz 4158
33 : chalabi 4903 # special treatment when x has one row because apply returns a vector
34 :     if (NCOL(x) > 1)
35 :     t(ans)
36 :     else
37 :     matrix(ans, ncol = 1, dimnames = dimnames(x))
38 :     })
39 :    
40 : wuertz 4158 # ------------------------------------------------------------------------------
41 :    
42 : chalabi 4903 setMethod("rowCumsums", "timeSeries", function(x, na.rm = FALSE, ...)
43 :     setDataPart(x, callGeneric(getDataPart(x), na.rm = na.rm, ...)))
44 : wuertz 4158
45 :     ################################################################################
46 :    

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge