[R-gregmisc-users] SF.net SVN: r-gregmisc:[1896] trunk/gtools/R/first.R
Brought to you by:
warnes
From: <wa...@us...> - 2014-10-09 18:53:00
|
Revision: 1896 http://sourceforge.net/p/r-gregmisc/code/1896 Author: warnes Date: 2014-10-09 18:52:58 +0000 (Thu, 09 Oct 2014) Log Message: ----------- Make right() and left() S3 methods for classes data.frame and matrix Modified Paths: -------------- trunk/gtools/R/first.R Modified: trunk/gtools/R/first.R =================================================================== --- trunk/gtools/R/first.R 2014-09-17 22:26:29 UTC (rev 1895) +++ trunk/gtools/R/first.R 2014-10-09 18:52:58 UTC (rev 1896) @@ -1,21 +1,26 @@ first <- function(x) UseMethod("first") last <- function(x) UseMethod("last") +left <- function(x, n) UseMethod("left") +right <- function(x, n) UseMethod("left") first.default <- function(x) x[1] -last.default <- function(x) x[length(x)] +last.default <- function(x) x[length(x)] -first.list <- function(x) x[[1]] -last.list <- function(x) x[[length(x)]] +first.list <- function(x, ...) x[[1]] +last.list <- function(x, ...) x[[length(x)]] -left <- function(x, n=6) + +left.data.frame <- function(x, n=6) { n <- min(n, ncol(x)) x[, 1:n] } +left.matrix <- left.data.frame -right <- function(x, n=6) +right.data.frame <- function(x, n=6) { n <- min(n, ncol(x)) x[, (ncol(x)-n+1):ncol(x)] } +right.matrix <- right.data.frame This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |