Skip to content

Commit

Permalink
Update docs and release
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Feb 24, 2009
1 parent d6c04e1 commit 5957086
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion NEWS
@@ -1,4 +1,4 @@
plyr 0.1.5 (2008-XX-XX) --------------------------------------------------- plyr 0.1.5 (2008-02-23) ---------------------------------------------------


* colwise now accepts a quoted list as its second argument. This allows you to specify the names of columns to work on: colwise(mean, .(lat, long)) * colwise now accepts a quoted list as its second argument. This allows you to specify the names of columns to work on: colwise(mean, .(lat, long))
* d_ply and a_ply now correctly pass ... to the function * d_ply and a_ply now correctly pass ... to the function
Expand Down
34 changes: 31 additions & 3 deletions man/colwise-5m.rd
Expand Up @@ -8,14 +8,42 @@
\description{ \description{
Turn a function that operates on a vector into a function that operates column-wise on a data.frame Turn a function that operates on a vector into a function that operates column-wise on a data.frame
} }
\usage{colwise(.fun, .if = function(x) TRUE)} \usage{colwise(.fun, .cols = function(x) TRUE)}
\arguments{ \arguments{
\item{.fun}{function} \item{.fun}{function}
\item{.if}{function that tests columns for inclusion} \item{.cols}{either function that tests columns for inclusion, or a quoted object giving which columns to process}
} }


\details{\code{catcolwise} and \code{numcolwise} provide version that only operate \details{\code{catcolwise} and \code{numcolwise} provide version that only operate
on discrete and numeric variables respectively} on discrete and numeric variables respectively}


\examples{} \examples{# Count number of missing values
nmissing <- function(x) sum(is.na(x))

# Apply to every column in a data frame
colwise(nmissing)(baseball)
# This syntax looks a little different. It is shorthand for the
# the following:
f <- colwise(nmissing)
f(baseball)

# This is particularly useful in conjunction with d*ply
ddply(baseball, .(year), colwise(nmissing))

# To operate only on specified columns, supply them as the second
# argument. Many different forms are accepted.
ddply(baseball, .(year), colwise(nmissing, .(sb, cs, so)))
ddply(baseball, .(year), colwise(nmissing, c("sb", "cs", "so")))
ddply(baseball, .(year), colwise(nmissing, ~ sb + cs + so))

# Alternatively, you can specify a boolean function that determines
# whether or not a column should be included
ddply(baseball, .(year), colwise(nmissing, is.character))
ddply(baseball, .(year), colwise(nmissing, is.numeric))
ddply(baseball, .(year), colwise(nmissing, is.discrete))

# These last two cases are particularly common, so some shortcuts are
# provided:
ddply(baseball, .(year), numcolwise(nmissing))
ddply(baseball, .(year), catcolwise(nmissing))}


0 comments on commit 5957086

Please sign in to comment.