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 https://had.co.nz/plyr/, or track development at https://github.com/hadley/plyr. You can ask questions about plyr (and data manipulation in general) on the plyr mailing list. Sign up at https://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

385,900

Version

1.8.7

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

March 24th, 2022

Functions in plyr (1.8.7)

a_ply

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

Convert input to quoted variables.
amv_dimnames

Dimension names.
arrange

Order a data frame by its colums.
aaply

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

Convert split list to regular list.
amv_dim

Dimensions.
as.data.frame.function

Make a function return a data frame.
alply

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

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

Yearly batting records for all major league baseball players
daply

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

Column-wise function.
desc

Descending order.
defaults

Set defaults.
here

Capture current evaluation context.
[.split

Subset splits.
ddply

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

Number of dimensions.
dlply

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

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

Numeric id for a vector.
create_progress_bar

Create progress bar.
id

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

Aggregate multiple functions into a single function.
compact

Compact list.
isplit2

Split iterator that returns values, not indices.
empty

Check if a data frame is empty.
eval.quoted

Evaluate a quoted list of variables.
count

Count the number of occurences.
is.formula

Is a formula? Checks if argument is a formula
failwith

Fail with specified value.
indexed_df

An indexed data frame.
is.discrete

Determine if a vector is discrete.
join_all

Recursively join a list of data frames.
l_ply

Split list, apply function, and discard results.
ldply

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

An indexed array.
idata.frame

Construct an immutable data frame.
laply

Split list, apply function, and return results in an array.
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.
list_to_vector

List to vector.
join.keys

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

List to data frame.
join

Join two data frames together.
ozone

Monthly ozone measurements over Central America.
plyr-deprecated

Deprecated Functions in Package plyr
list_to_array

List to array.
liply

Experimental iterator based version of llply.
names.quoted

Compute names of quoted variables.
nunique

Number of unique values.
.

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

Quick data frame.
mapvalues

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

Extract matching rows of a data frame.
reduce_dim

Reduce dimensions.
rdply

Replicate expression and return results in a data frame.
llply

Split list, apply function, and return results in a list.
loop_apply

Loop apply
mdply

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

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

Split indices.
splat

`Splat' arguments to a function.
rbind.fill.matrix

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

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

Remove splitting variables from a data frame.
plyr

plyr: the split-apply-combine paradigm for R.
print.quoted

Print quoted variables.
splitter_d

Split a data frame by variables.
progress_text

Text progress bar.
name_rows

Toggle row names between explicit and implicit.
summarise

Summarise a data frame.
progress_time

Text progress bar with time.
vaggregate

Vector aggregate.
rlply

Replicate expression and return results in a list.
round_any

Round to multiple of any number.
print.split

Print split.
mlply

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

Null progress bar
take

Take a subset along an arbitrary dimension
tryapply

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

Modify names by name, not position.
revalue

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

Graphical progress bar, powered by Tk.
split_labels

Generate labels for split data frame.
unrowname

Un-rowname.
splitter_a

Split an array by .margins.
progress_win

Graphical progress bar, powered by Windows.
r_ply

Replicate expression and discard results.
raply

Replicate expression and return results in a array.
true

Function that always returns true.
try_default

Try, with default in case of error.