Questions tagged [plyr]

plyr is an R package with tools to solve a variety of problems using the split-apply-combine strategy

plyr is an R package written by Hadley Wickham which contains tools to solve a variety of problems using the strategy of split, apply and combine:

  • Split a data structure (data frame, list, array) into smaller pieces;
  • Apply a function to each piece; then
  • Combine the results into a data structure.

It partially replaces the apply family of functions (lapply, tapply, Map, etc.) in base-R, and is partially succeeded by .

Repositories

Other resources

Related tags

2465 questions
1
vote
3 answers

ddply with fixed number of rows

I want to break up my data by 'number of rows'. That is to say I want to send a fixed number of rows to my function and when I get to the end of the data frame (last chunk) I need to just send the chunk whether it has the fixed number of rows or…
James
  • 1,447
  • 3
  • 16
  • 30
1
vote
2 answers

R using 't' with ddply

I need to transform some data like this: df<-data.frame(Plate=c("4660", "4660", "4660", "4660", "4660", "4660", "4660", "4660", "4660", "4660", "4660"), Well=c("A1", "A2", "A3", "A4", "B1", "B2", "B3", "C1", "C2", "C3", "C4"), Result=c(1, 10, 100,…
James
  • 1,447
  • 3
  • 16
  • 30
1
vote
3 answers

How can I apply different aggregate functions to different columns in R?

How can I apply different aggregate functions to different columns in R? The aggregate() function only offers one function argument to be passed: V1 V2 V3 1 18.45022 62.24411694 2 90.34637 20.86505214 1 50.77358 27.30074987 2 …
barbaz
  • 1,642
  • 2
  • 17
  • 27
1
vote
1 answer

R: Using several criteria for the Aggregate function

I am searching for a solution how to use the aggregate function to sum up a column given several criteria in other columns. R should select a range in a column and executean operation in the same rows considering the value from another row. The…
Fabian Stolz
  • 1,935
  • 7
  • 27
  • 30
1
vote
1 answer

R: using ddply in a loop over data frame columns

I need to calculate and add to a data frame multiple new columns based on the values in each column in a subset of columns in the data frame. These columns all hold time series data (there is a common date column). For example I need to calculate…
SlowLearner
  • 7,907
  • 11
  • 49
  • 80
1
vote
1 answer

parallel using plyr

I am reading in an XML file and want to try and improve the performance using foreach and doSNOW, however when using plyr I encounter an error. I think it might be because I have missed a way to send the functions and packages to the…
Sam35
  • 35
  • 7
1
vote
0 answers

Using plyr with Barnard's test

I was doing some social science research and stumbled upon an article discussing the different exact tests, including Bernard's test. Several authors have discussed the differences between Fisher's Exact test and Bernard's test (Lydersen in 2009,…
1
vote
1 answer

plyr R empty inner join

I got a big data table X (504x9) and a smaller data frame bzShare (323X4) both with the columns top.sector and sizeClass. Now i want to join a value from bzShare into X so that the dimensions of X are (504x10). An inner join selects only rows with…
Markus Graf
  • 533
  • 3
  • 16
1
vote
2 answers

Determine which element is max, through ddply

I have a data frame that contains ID variables, timepoints, and response values. I'm using some old code that uses ddply to calculate the maximum mean values for each ID variable (i.e., the timepoint with the highest response in each group): grp <-…
Drew Steen
  • 16,045
  • 12
  • 62
  • 90
1
vote
2 answers

R Table modification

How do I take the average of a few entries in a column whose corresponding entry in another column,has the same entries? For instance I have a large table with say 3 columns, time and prices being 2. and lets say under the time column the values…
Probabilityman
  • 361
  • 1
  • 5
  • 7
1
vote
1 answer

How do I create a function for plyr

I have a series of soccer results and wish to find out how many points a team has scored in a particular number of games Here is the head of a subset with the cumulative points scored during a season since the latest result I have been…
pssguy
  • 3,455
  • 7
  • 38
  • 68
1
vote
0 answers

Are gls and dynlm calls technically different (not speaking of the stats sense)?

I wrote a small function to run multiple univariate regressions with different lags: f <- function(x,l) { lm.obj <- dynlm(GNP~L(get(as.character(x)),l), data=longley) names(lm.obj$coefficients)[2] <-…
Matt Bannert
  • 27,631
  • 38
  • 141
  • 207
1
vote
1 answer

ddply for transforming data

I've the following test data frame. id1 val A 1 A 1 A 1 A 1 B 2 B 2 B 2 B 2 I would like to transform it to a data frame as shown below. id1 val A 1 A 1 A 2 A 2 B 3 B 3 B 4 B 4 What I've done is to first find the…
broccoli
  • 4,738
  • 10
  • 42
  • 54
1
vote
1 answer

passing a list argument to llply

I've never found a satisfactory answer to this question. Assuming I have a function: foo <- function(a,b,c) { ... } a is a list containing many data.frame objects b is a list containing a special class of data (class ppp from library spatstat if…
Maiasaura
  • 32,226
  • 27
  • 104
  • 108
0
votes
1 answer

dlply syntax with t.test

I clearly still don't understand plyr syntax, as illustrated below. Can someone help me see what I'm missing? The following code works fine, as expected: # make a data frame to use dlply on f <- as.factor(c(rep("a", 3), rep("b", 3))) y <-…
Drew Steen
  • 16,045
  • 12
  • 62
  • 90
1 2 3
99
100