[R-gregmisc-users] SF.net SVN: r-gregmisc:[1618] trunk/gdata
Brought to you by:
warnes
From: <wa...@us...> - 2012-09-20 15:39:54
|
Revision: 1618 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1618&view=rev Author: warnes Date: 2012-09-20 15:39:43 +0000 (Thu, 20 Sep 2012) Log Message: ----------- Add 'ans()' and 'duplicated()' contributed by Liviu Andronic. Added Paths: ----------- trunk/gdata/R/ans.R trunk/gdata/R/duplicated2.R trunk/gdata/man/ans.Rd trunk/gdata/man/duplicated2.Rd Added: trunk/gdata/R/ans.R =================================================================== --- trunk/gdata/R/ans.R (rev 0) +++ trunk/gdata/R/ans.R 2012-09-20 15:39:43 UTC (rev 1618) @@ -0,0 +1 @@ +ans <- function() .Last.value Added: trunk/gdata/R/duplicated2.R =================================================================== --- trunk/gdata/R/duplicated2.R (rev 0) +++ trunk/gdata/R/duplicated2.R 2012-09-20 15:39:43 UTC (rev 1618) @@ -0,0 +1,8 @@ +duplicated2 <- function(x, bothWays=TRUE, ...) + { + if(!bothWays) { + return(duplicated(x, ...)) + } else if(bothWays) { + return((duplicated(x, ...) | duplicated(x, fromLast=TRUE, ...))) + } + } Added: trunk/gdata/man/ans.Rd =================================================================== --- trunk/gdata/man/ans.Rd (rev 0) +++ trunk/gdata/man/ans.Rd 2012-09-20 15:39:43 UTC (rev 1618) @@ -0,0 +1,34 @@ +\name{ans} +\alias{ans} +\title{Value of Last Evaluated Expression} +\usage{ +ans() +} +\description{ + The functon returns the value of the last evaluated \emph{top-level} + expression, which is always assigned to \code{.Last.value} (in + \code{package:base}). +} +\details{ + This function retrieves \code{.Last.value}. For more details see + \code{\link{Last.value}}. +} +\value{ + \code{.Last.value} +} +\seealso{ + \code{\link{Last.value}}, \code{\link{eval}} +} +\author{Liviu Andronic} +\examples{ + 2+2 # Trivial calculation... + ans() # See the answer again + + gamma(1:15) # Some intensive calculation... + fac14 <- ans() # store the results into a variable + + rnorm(20) # Generate some standard normal values + ans()^2 # Convert to Chi-square(1) values... + stem(ans()) # Now show a stem-and-leaf table +} +\keyword{programming} Added: trunk/gdata/man/duplicated2.Rd =================================================================== --- trunk/gdata/man/duplicated2.Rd (rev 0) +++ trunk/gdata/man/duplicated2.Rd 2012-09-20 15:39:43 UTC (rev 1618) @@ -0,0 +1,51 @@ +\name{duplicated2} +\alias{duplicated2} +\title{Determine Duplicate Elements} +\description{ + \code{duplicated2()} determines which elements of a vector or data + frame are duplicates, and returns a logical vector indicating which + elements (rows) are duplicates. +} +\usage{ +duplicated2(x, bothWays=TRUE, ...) +} +\arguments{ + \item{x}{a vector or a data frame or an array or \code{NULL}.} + \item{bothWays}{if \code{TRUE} (the default), duplication should be + considered from both sides. For more information see the argument \code{fromLast} + to the function \code{\link{duplicated}}.} + \item{\dots}{further arguments passed down to \code{duplicated()} and + its methods.} +} +\details{ + The standard \code{\link{duplicated}} function (in \code{package:base}) + only returns \code{TRUE} for the second and following copies of each + duplicated value (second-to-last and earlier when + \code{fromLast=TRUE}). This function returns all duplicated + elementes, including the first (last) value. + + When \code{bothWays} is \code{FALSE}, \code{duplicated2()} defaults to + a \code{\link{duplicated}} call. When \code{bothWays} is \code{TRUE}, + the following call is being executed: + \code{duplicated(x, ...) | duplicated(x, fromLast=TRUE, ...)} +} +\value{ + For a vector input, a logical vector of the same length as + \code{x}. For a data frame, a logical vector with one element for + each row. For a matrix or array, and when \code{MARGIN = 0}, a + logical array with the same dimensions and dimnames. + + For more details see \code{\link{duplicated}}. +} +\seealso{ + \code{\link{duplicated}}, \code{\link{unique}} +} +\author{Liviu Andronic} +\examples{ + data(iris) + iris[duplicated(iris), ] # 2nd duplicated value + iris[duplicated(iris, fromLast=TRUE), ] # 1st duplicated value + iris[duplicated2(iris), ] # both duplicated values +} +\keyword{logic} +\keyword{manip} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |