Browse files

Update docs and release

  • Loading branch information...
1 parent d6c04e1 commit 59570864bf504d00c83d051f014290ea550c4aad @hadley committed Feb 24, 2009
Showing with 32 additions and 4 deletions.
  1. +1 −1 NEWS
  2. +31 −3 man/colwise-5m.rd
@@ -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))
* d_ply and a_ply now correctly pass ... to the function
@@ -8,14 +8,42 @@
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)}
-\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
on discrete and numeric variables respectively}
+\examples{# Count number of missing values
+nmissing <- function(x) sum(
+# Apply to every column in a data frame
+# This syntax looks a little different. It is shorthand for the
+# the following:
+f <- colwise(nmissing)
+# 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.