[Xts-commits] r642 - pkg/xtsExtra/R/xtsdf

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 19 20:17:07 CEST 2012


Author: weylandt
Date: 2012-06-19 20:17:07 +0200 (Tue, 19 Jun 2012)
New Revision: 642

Modified:
   pkg/xtsExtra/R/xtsdf/subset.print.xtsdf.R
Log:
Subset method for xtsdf relying heavily on xts

Modified: pkg/xtsExtra/R/xtsdf/subset.print.xtsdf.R
===================================================================
--- pkg/xtsExtra/R/xtsdf/subset.print.xtsdf.R	2012-06-19 17:33:50 UTC (rev 641)
+++ pkg/xtsExtra/R/xtsdf/subset.print.xtsdf.R	2012-06-19 18:17:07 UTC (rev 642)
@@ -15,7 +15,22 @@
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-`[.xtsdf` <- function(x, i, k, drop = FALSE, which.i = FALSE, ...){}
+`[.xtsdf` <- function(x, i, j, drop = FALSE, which.i = FALSE, ...){
+  if(missing(i)) {
+    x <- unclass(x)[j]
+    class(x) <- "xtsdf"
+    return(x)
+  }
+     
+  x <- x[,j]
+     
+  # For now simply loop over x and use i as appropriate
+  ans <- lapply(x, function(x) x[i = i, drop = drop, which.i = which.i, ...])   
+  class(ans) <- "xtsdf"
+  
+  ans
+  
+}
 
 print.xtsdf <- function(x, ...){
   print(as.data.frame(x, row.names = index(x)), ...)



More information about the Xts-commits mailing list