Learn R Programming

⚠️There's a newer version (1.8.9) of this package.Take me there.

plyr

plyr is a set of tools for a common set of problems: you need to split up a big data structure into homogeneous pieces, apply a function to each piece and then combine all the results back together. For example, you might want to:

  • fit the same model each patient subsets of a data frame
  • quickly calculate summary statistics for each group
  • perform group-wise transformations like scaling or standardising

It's already possible to do this with base R functions (like split and the apply family of functions), but plyr makes it all a bit easier with:

  • totally consistent names, arguments and outputs
  • convenient parallelisation through the foreach package
  • input from and output to data.frames, matrices and lists
  • progress bars to keep track of long running operations
  • built-in error recovery, and informative error messages
  • labels that are maintained across all transformations

Considerable effort has been put into making plyr fast and memory efficient, and in many cases plyr is as fast as, or faster than, the built-in equivalents.

A detailed introduction to plyr has been published in JSS: "The Split-Apply-Combine Strategy for Data Analysis", http://www.jstatsoft.org/v40/i01/. You can find out more at http://had.co.nz/plyr/, or track development at http://github.com/hadley/plyr. You can ask questions about plyr (and data manipulation in general) on the plyr mailing list. Sign up at http://groups.google.com/group/manipulatr.

Status

plyr is retired: this means only changes necessary to keep it on CRAN will be made. We recommend using dplyr (for data frames) or purrr (for lists) instead.

Copy Link

Version

Install

install.packages('plyr')

Monthly Downloads

462,444

Version

1.8.6

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Hadley Wickham

Last Published

March 3rd, 2020

Functions in plyr (1.8.6)

amv_dim

Dimensions.
is.discrete

Determine if a vector is discrete.
indexed_df

An indexed data frame.
d_ply

Split data frame, apply function, and discard results.
arrange

Order a data frame by its colums.
defaults

Set defaults.
each

Aggregate multiple functions into a single function.
empty

Check if a data frame is empty.
as.data.frame.function

Make a function return a data frame.
loop_apply

Loop apply
desc

Descending order.
eval.quoted

Evaluate a quoted list of variables.
llply

Split list, apply function, and return results in a list.
plyr-deprecated

Deprecated Functions in Package plyr
ozone

Monthly ozone measurements over Central America.
plyr

plyr: the split-apply-combine paradigm for R.
failwith

Fail with specified value.
adply

Split array, apply function, and return results in a data frame.
a_ply

Split array, apply function, and discard results.
print.quoted

Print quoted variables.
indexed_array

An indexed array.
liply

Experimental iterator based version of llply.
alply

Split array, apply function, and return results in a list.
aaply

Split array, apply function, and return results in an array.
mutate

Mutate a data frame by adding new or replacing existing columns.
list_to_array

List to array.
idata.frame

Construct an immutable data frame.
rdply

Replicate expression and return results in a data frame.
reduce_dim

Reduce dimensions.
compact

Compact list.
tryapply

Apply with built in try. Uses compact, lapply and tryNULL
true

Function that always returns true.
name_rows

Toggle row names between explicit and implicit.
count

Count the number of occurences.
colwise

Column-wise function.
daply

Split data frame, apply function, and return results in an array.
try_default

Try, with default in case of error.
progress_tk

Graphical progress bar, powered by Tk.
dims

Number of dimensions.
unrowname

Un-rowname.
progress_win

Graphical progress bar, powered by Windows.
baseball

Yearly batting records for all major league baseball players
[.split

Subset splits.
here

Capture current evaluation context.
dlply

Split data frame, apply function, and return results in a list.
ddply

Split data frame, apply function, and return results in a data frame.
id

Compute a unique numeric id for each unique row in a data frame.
join_all

Recursively join a list of data frames.
r_ply

Replicate expression and discard results.
raply

Replicate expression and return results in a array.
list_to_dataframe

List to data frame.
mapvalues

Replace specified values with new values, in a vector or factor.
match_df

Extract matching rows of a data frame.
split_labels

Generate labels for split data frame.
join

Join two data frames together.
l_ply

Split list, apply function, and discard results.
join.keys

Join keys. Given two data frames, create a unique key for each row.
list_to_vector

List to vector.
splat

`Splat' arguments to a function.
id_var

Numeric id for a vector.
progress_none

Null progress bar
print.split

Print split.
is.formula

Is a formula? Checks if argument is a formula
laply

Split list, apply function, and return results in an array.
rlply

Replicate expression and return results in a list.
splitter_a

Split an array by .margins.
split_indices

Split indices.
isplit2

Split iterator that returns values, not indices.
progress_text

Text progress bar.
m_ply

Call function with arguments in array or data frame, discarding results.
maply

Call function with arguments in array or data frame, returning an array.
mdply

Call function with arguments in array or data frame, returning a data frame.
ldply

Split list, apply function, and return results in a data frame.
mlply

Call function with arguments in array or data frame, returning a list.
names.quoted

Compute names of quoted variables.
round_any

Round to multiple of any number.
nunique

Number of unique values.
progress_time

Text progress bar with time.
quickdf

Quick data frame.
revalue

Replace specified values with new values, in a factor or character vector.
rename

Modify names by name, not position.
.

Quote variables to create a list of unevaluated expressions for later evaluation.
summarise

Summarise a data frame.
vaggregate

Vector aggregate.
take

Take a subset along an arbitrary dimension
rbind.fill.matrix

Bind matrices by row, and fill missing columns with NA.
splitter_d

Split a data frame by variables.
strip_splits

Remove splitting variables from a data frame.
rbind.fill

Combine data.frames by row, filling in missing columns.
create_progress_bar

Create progress bar.
as.list.split

Convert split list to regular list.
as.quoted

Convert input to quoted variables.
amv_dimnames

Dimension names.