Learn R Programming

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.9

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

October 2nd, 2023

Functions in plyr (1.8.9)

daply

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

Column-wise function.
desc

Descending order.
baseball

Yearly batting records for all major league baseball players
create_progress_bar

Create progress bar.
defaults

Set defaults.
ddply

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

Compact list.
count

Count the number of occurences.
here

Capture current evaluation context.
each

Aggregate multiple functions into a single function.
eval.quoted

Evaluate a quoted list of variables.
l_ply

Split list, apply function, and discard results.
empty

Check if a data frame is empty.
id

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

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

Number of dimensions.
join_all

Recursively join a list of data frames.
is.discrete

Determine if a vector is discrete.
join.keys

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

Numeric id for a vector.
indexed_df

An indexed data frame.
failwith

Fail with specified value.
[.split

Subset splits.
llply

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

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

Join two data frames together.
idata.frame

Construct an immutable data frame.
list_to_array

List to array.
isplit2

Split iterator that returns values, not indices.
liply

Experimental iterator based version of llply.
maply

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

Is a formula? Checks if argument is a formula
m_ply

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

Loop apply
indexed_array

An indexed array.
list_to_vector

List to vector.
list_to_dataframe

List to data frame.
ldply

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

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

Deprecated Functions in Package plyr
ozone

Monthly ozone measurements over Central America.
mdply

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

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

Graphical progress bar, powered by Tk.
progress_win

Graphical progress bar, powered by Windows.
names.quoted

Compute names of quoted variables.
print.quoted

Print quoted variables.
plyr

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

Number of unique values.
progress_text

Text progress bar.
progress_time

Text progress bar with time.
mapvalues

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

Extract matching rows of a data frame.
mutate

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

Toggle row names between explicit and implicit.
print.split

Print split.
quickdf

Quick data frame.
rlply

Replicate expression and return results in a list.
round_any

Round to multiple of any number.
rbind.fill

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

Null progress bar
split_labels

Generate labels for split data frame.
rdply

Replicate expression and return results in a data frame.
raply

Replicate expression and return results in a array.
rbind.fill.matrix

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

Reduce dimensions.
r_ply

Replicate expression and discard results.
splitter_a

Split an array by .margins.
rename

Modify names by name, not position.
.

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

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

`Splat' arguments to a function.
true

Function that always returns true.
vaggregate

Vector aggregate.
split_indices

Split indices.
summarise

Summarise a data frame.
try_default

Try, with default in case of error.
take

Take a subset along an arbitrary dimension
splitter_d

Split a data frame by variables.
strip_splits

Remove splitting variables from a data frame.
tryapply

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

Un-rowname.
as.quoted

Convert input to quoted variables.
adply

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

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

Dimensions.
amv_dimnames

Dimension names.
aaply

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

Split array, apply function, and discard results.
as.data.frame.function

Make a function return a data frame.
arrange

Order a data frame by its colums.
as.list.split

Convert split list to regular list.