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

381,014

Version

1.8.8

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

November 11th, 2022

Functions in plyr (1.8.8)

as.data.frame.function

Make a function return a data frame.
as.quoted

Convert input to quoted variables.
amv_dimnames

Dimension names.
amv_dim

Dimensions.
aaply

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

Convert split list to regular list.
a_ply

Split array, apply function, and discard results.
alply

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

Order a data frame by its colums.
adply

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

Set defaults.
ddply

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

Create progress bar.
count

Count the number of occurences.
colwise

Column-wise function.
compact

Compact list.
baseball

Yearly batting records for all major league baseball players
desc

Descending order.
d_ply

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

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

Fail with specified value.
eval.quoted

Evaluate a quoted list of variables.
empty

Check if a data frame is empty.
[.split

Subset splits.
each

Aggregate multiple functions into a single function.
join_all

Recursively join a list of data frames.
dims

Number of dimensions.
id_var

Numeric id for a vector.
id

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

An indexed data frame.
l_ply

Split list, apply function, and discard results.
is.discrete

Determine if a vector is discrete.
here

Capture current evaluation context.
llply

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

Loop apply
indexed_array

An indexed array.
list_to_dataframe

List to data frame.
idata.frame

Construct an immutable data frame.
is.formula

Is a formula? Checks if argument is a formula
isplit2

Split iterator that returns values, not indices.
laply

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

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

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

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

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

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

Join two data frames together.
plyr-deprecated

Deprecated Functions in Package plyr
ozone

Monthly ozone measurements over Central America.
liply

Experimental iterator based version of llply.
progress_time

Text progress bar with time.
plyr

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

Graphical progress bar, powered by Tk.
progress_win

Graphical progress bar, powered by Windows.
mutate

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

Toggle row names between explicit and implicit.
rbind.fill

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

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

List to array.
progress_text

Text progress bar.
mdply

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

Print split.
progress_none

Null progress bar
nunique

Number of unique values.
names.quoted

Compute names of quoted variables.
reduce_dim

Reduce dimensions.
rdply

Replicate expression and return results in a data frame.
print.quoted

Print quoted variables.
true

Function that always returns true.
rbind.fill.matrix

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

Try, with default in case of error.
split_labels

Generate labels for split data frame.
round_any

Round to multiple of any number.
rlply

Replicate expression and return results in a list.
raply

Replicate expression and return results in a array.
r_ply

Replicate expression and discard results.
splitter_a

Split an array by .margins.
take

Take a subset along an arbitrary dimension
summarise

Summarise a data frame.
splitter_d

Split a data frame by variables.
splat

`Splat' arguments to a function.
split_indices

Split indices.
strip_splits

Remove splitting variables from a data frame.
tryapply

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

Un-rowname.
mapvalues

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

Extract matching rows of a data frame.
list_to_vector

List to vector.
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.
vaggregate

Vector aggregate.