[R-gregmisc-users] SF.net SVN: r-gregmisc: [988] trunk/gdata
Brought to you by:
warnes
|
From: <gg...@us...> - 2006-10-29 12:55:20
|
Revision: 988
http://svn.sourceforge.net/r-gregmisc/?rev=988&view=rev
Author: ggorjan
Date: 2006-10-29 04:55:08 -0800 (Sun, 29 Oct 2006)
Log Message:
-----------
Fixed collision bug with stats version of reorder.factor
Modified Paths:
--------------
trunk/gdata/NEWS
trunk/gdata/R/reorder.R
trunk/gdata/man/reorder.Rd
Modified: trunk/gdata/NEWS
===================================================================
--- trunk/gdata/NEWS 2006-10-27 21:15:22 UTC (rev 987)
+++ trunk/gdata/NEWS 2006-10-29 12:55:08 UTC (rev 988)
@@ -1,3 +1,13 @@
+CHANGES IN 2.3.1 (2006-10-29)
+---------------------------------------
+
+- Arguments as well as their position of reorder.factor have been changed
+ to conform with reorder.factor method in stats package, due to collision
+ bug. Argument 'make.ordered' is now 'order' and old argument 'order' is
+ now 'new.order'! Therefore, you have to implicitly specify new.order i.e.
+
+ reorder(trt, new.order=c("PLACEBO", "300 MG", "600 MG", "1200 MG"))
+
CHANGES FROM 2.1.X to 2.3.0 (2006-09-19)
---------------------------------------
@@ -12,7 +22,7 @@
- Extended trim() to handle a variety of data types data.frames,
lists, factors, etc. Code changes contributed by Gregor Gorjanc.
-
+
- Added resample() command that acts like sample() except that it
_always_ samples from the arguments provided, even if only a single
argument is present. This differs from sample() which behaves
@@ -54,6 +64,4 @@
- Updated ll.Rd documentation
- - Fixed bug in Args.R, is.what.R, ll.R
-
-
+ - Fixed bug in Args.R, is.what.R, ll.R
Modified: trunk/gdata/R/reorder.R
===================================================================
--- trunk/gdata/R/reorder.R 2006-10-27 21:15:22 UTC (rev 987)
+++ trunk/gdata/R/reorder.R 2006-10-29 12:55:08 UTC (rev 988)
@@ -3,31 +3,26 @@
# Reorder the levels of a factor.
reorder.factor <- function(x,
- order,
X,
FUN,
- sort=mixedsort,
- make.ordered = is.ordered(x),
- ... )
- {
- constructor <- if (make.ordered) ordered else factor
+ ...,
+ order=is.ordered(x),
+ new.order,
+ sort=mixedsort)
+{
+ constructor <- if (order) ordered else factor
- if (!missing(order))
+ if (!missing(new.order))
{
- if (is.numeric(order))
- order = levels(x)[order]
+ if (is.numeric(new.order))
+ new.order <- levels(x)[new.order]
else
- order = order
+ new.order <- new.order
}
else if (!missing(FUN))
- order = names(sort(tapply(X, x, FUN, ...)))
+ new.order <- names(sort(tapply(X, x, FUN, ...)))
else
- order = sort(levels(x))
+ new.order <- sort(levels(x))
- constructor( x, levels=order)
-
- }
-
-
-
-
+ constructor(x, levels=new.order)
+}
Modified: trunk/gdata/man/reorder.Rd
===================================================================
--- trunk/gdata/man/reorder.Rd 2006-10-27 21:15:22 UTC (rev 987)
+++ trunk/gdata/man/reorder.Rd 2006-10-29 12:55:08 UTC (rev 988)
@@ -1,6 +1,5 @@
% $Id$
-
\name{reorder.factor}
\alias{reorder.factor}
\title{Reorder the Levels of a Factor}
@@ -9,61 +8,61 @@
}
\usage{
\method{reorder}{factor}(x,
- order,
X,
FUN,
- sort=mixedsort,
- make.ordered = is.ordered(x),
- ... )
+ ...,
+ order=is.ordered(x),
+ new.order,
+ sort=mixedsort)
}
\arguments{
- \item{x}{factor.}
- \item{order}{A vector of indexes or a vector of label names giving the
- order of the new factor levels.}
+ \item{x}{factor}
\item{X}{auxillary data vector}
\item{FUN}{function to be applied to subsets of \code{X} determined by
- \code{x}, to determine factor order.}
- \item{sort}{function to use to sort the factor level names}
- \item{make.ordered}{logical value indicating whether the returned
- object should be an \code{'ordered'} factor.}
- \item{...}{Optional parameters to FUN.}
+ \code{x}, to determine factor order}
+ \item{...}{optional parameters to \code{FUN}}
+ \item{order}{logical value indicating whether the returned
+ object should be an \code{\link{ordered}} factor}
+ \item{new.order}{a vector of indexes or a vector of label names giving
+ the order of the new factor levels}
+ \item{sort}{function to use to sort the factor level names, used only
+ when \code{new.order} is missing}
}
\details{
- This function changes the order of the levels of a factor. It can do
- so via three different mechanisms, depending on whether \code{order},
- \code{X} \emph{and} \code{FUN}, or \code{sort} are provided.
+ This function changes the order of the levels of a factor. It can do
+ so via three different mechanisms, depending on whether, \code{X}
+ \emph{and} \code{FUN}, \code{new.order} or \code{sort} are provided.
- If \code{order} is provided: For a numeric vector, the new factor level names
- are constructed by reordering the factor levels according to the
- numeric values. For vectors, \code{order} gives the list of new factor
- level names. In either case levels omitted from \code{order} will
- become missing values.
-
If \code{X} \emph{and} \code{Fun} are provided: The data in \code{X}
- is grouped by the levels of \code{data} and \code{FUN} is applied.
+ is grouped by the levels of \code{x} and \code{FUN} is applied.
The groups are then sorted by this value, and the resulting order is
used for the new factor level names.
+ If \code{new.order} is provided: For a numeric vector, the new factor
+ level names are constructed by reordering the factor levels according
+ to the numeric values. For vectors, \code{new.order} gives the list of
+ new factor level names. In either case levels omitted from
+ \code{new.order} will become missing (\code{NA}) values.
+
If \code{sort} is provided (as it is by default): The new
factor level names are generated by applying the supplied function
- to the existing factor level names. With \code{order="mixedsort"} the
+ to the existing factor level names. With \code{sort=mixedsort} the
factor levels are sorted so that combined numeric and character
strings are sorted in according to character rules on the character
- sections (including ignoring case), and be numeric rules for the
- numeric sections. See \code{mixedsort} for details.
-
+ sections (including ignoring case), and the numeric rules for the
+ numeric sections. See \code{\link[gtools]{mixedsort}} for details.
}
\value{
- A new factor with the levels ordered as specified.
+ A new factor with reordered levels
}
-\author{ Gregory R. Warnes \email{wa...@bs...}}
+\author{Gregory R. Warnes \email{wa...@bs...}}
-\seealso{ \code{\link{factor}}, \code{\link[stats]{reorder}} }
+\seealso{\code{\link{factor}} and \code{\link[stats]{reorder}}}
\examples{
# Create a 4 level example factor
- trt <- factor( sample( c("PLACEBO","300 MG", "600 MG", "1200 MG"),
+ trt <- factor( sample( c("PLACEBO", "300 MG", "600 MG", "1200 MG"),
100, replace=TRUE ) )
summary(trt)
# Note that the levels are not in a meaningful order.
@@ -73,18 +72,17 @@
trt2 <- reorder(trt)
summary(trt2)
# using indexes:
- trt3 <- reorder(trt, c(4,2,3,1))
+ trt3 <- reorder(trt, new.order=c(4, 2, 3, 1))
summary(trt3)
# using label names:
- trt4 <- reorder(trt, c("PLACEBO","300 MG", "600 MG", "1200 MG") )
+ trt4 <- reorder(trt, new.order=c("PLACEBO", "300 MG", "600 MG", "1200 MG"))
summary(trt4)
# using frequency
trt5 <- reorder(trt, X=as.numeric(trt), FUN=length)
summary(trt5)
-
# drop out the '300 MG' level
- trt6 <- reorder(trt, c("PLACEBO", "600 MG", "1200 MG") )
+ trt6 <- reorder(trt, new.order=c("PLACEBO", "600 MG", "1200 MG"))
summary(trt6)
}
\keyword{ manip }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|