[R-gregmisc-users] SF.net SVN: r-gregmisc:[1871] trunk/gtools
Brought to you by:
warnes
From: <wa...@us...> - 2014-08-27 00:36:44
|
Revision: 1871 http://sourceforge.net/p/r-gregmisc/code/1871 Author: warnes Date: 2014-08-27 00:36:40 +0000 (Wed, 27 Aug 2014) Log Message: ----------- Finish adding first(), last(), left(), and right(). Modified Paths: -------------- trunk/gtools/DESCRIPTION trunk/gtools/NAMESPACE trunk/gtools/R/first.R Added Paths: ----------- trunk/gtools/man/first.Rd trunk/gtools/man/left.Rd Modified: trunk/gtools/DESCRIPTION =================================================================== --- trunk/gtools/DESCRIPTION 2014-08-27 00:12:52 UTC (rev 1870) +++ trunk/gtools/DESCRIPTION 2014-08-27 00:36:40 UTC (rev 1871) @@ -1,8 +1,8 @@ Package: gtools Title: Various R programming tools Description: Various R programming tools -Version: 3.4.1 -Date: 2014-05-27 +Version: 3.4.2 +Date: 2014-08-26 Author: Gregory R. Warnes, Ben Bolker, and Thomas Lumley Maintainer: Gregory R. Warnes <gr...@wa...> License: LGPL-2.1 Modified: trunk/gtools/NAMESPACE =================================================================== --- trunk/gtools/NAMESPACE 2014-08-27 00:12:52 UTC (rev 1870) +++ trunk/gtools/NAMESPACE 2014-08-27 00:36:40 UTC (rev 1871) @@ -12,12 +12,15 @@ ddirichlet, defmacro, even, + first, foldchange, foldchange2logratio, getDependencies, inv.logit, invalid, keywords, + last, + left, lastAdd, logit, logratio2foldchange, @@ -27,6 +30,7 @@ permutations, permute, quantcut, + right, rdirichlet, running, scat, Modified: trunk/gtools/R/first.R =================================================================== --- trunk/gtools/R/first.R 2014-08-27 00:12:52 UTC (rev 1870) +++ trunk/gtools/R/first.R 2014-08-27 00:36:40 UTC (rev 1871) @@ -4,6 +4,9 @@ first.default <- function(x) x[1] last.default <- function(x) x[length(x)] +first.list <- function(x) x[[1]] +last.list <- function(x) x[[length(x)]] + left <- function(x, n=6) { n <- min(n, ncol(x)) @@ -13,5 +16,6 @@ right <- function(x, n=6) { n <- min(n, ncol(x)) - x[, (ncol(x)-n):ncol(x)] + x[, (ncol(x)-n+1):ncol(x)] } + Added: trunk/gtools/man/first.Rd =================================================================== --- trunk/gtools/man/first.Rd (rev 0) +++ trunk/gtools/man/first.Rd 2014-08-27 00:36:40 UTC (rev 1871) @@ -0,0 +1,43 @@ +\name{first} +\alias{first} +\alias{last} +\title{Return first or last element of a vector or list} +\description{ + Return first or last element of a vector or list +} +\usage{ +first(x) +last(x) +\method{first}{default}(x) +\method{last}{default}(x) +\method{first}{list}(x) +\method{last}{list}(x) +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + \item{x}{vector or list} +} +\value{ + The first or last element of \code{x}. +} +\author{ + Gregory R. Warnes \email{gr...@wa...} +} +\seealso{ + \code{\link[utils]{head}}, + \code{\link[utils]{tail}}, + \code{\link{left}}, + \code{\link{right}} +} +\examples{ +## works for vectors.. +v <- 1:10 +first(v) +last(v) + +## and for lists +l <- list(a=1, b=2, c=3) +first(l) +last(l) +} +\keyword{ manip } Added: trunk/gtools/man/left.Rd =================================================================== --- trunk/gtools/man/left.Rd (rev 0) +++ trunk/gtools/man/left.Rd 2014-08-27 00:36:40 UTC (rev 1871) @@ -0,0 +1,39 @@ +\name{left} +\alias{right} +\alias{left} +\title{Return the leftmost or rightmost columns of a matrix or dataframe} +\description{ + Return the leftmost or rightmost or columns of a matrix or dataframe +} +\usage{ +right(x, n = 6) +left(x, n=6) +} +\arguments{ + \item{x}{Matrix or dataframe} + \item{n}{Number of columns to return} +} +\value{ + An object consisting of the leftmost or rightmost \code{n} columns + of \code{x}. +} +\author{ + Gregory R. Warnes \email{gr...@wa...} +} +\seealso{ + \code{\link{first}}, + \code{\link{last}}, + \code{\link[utils]{head}}, + \code{\link[utils]{tail}} +} +\examples{ + m <- matrix( 1:100, ncol=10 ) + colnames(m) <- paste("Col",1:10, sep="_") + left(m) + right(m) + + d <- as.data.frame(m) + left(d) + right(d) +} +\keyword{ manip } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |