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
1 answer

Patterns for expression passing in R

Many R packages allow functions that take expressions as arguments. Some, however, go a step further. For example, the plyr package by @hadley boldly defines a function named .: > . function (..., .env = parent.frame()) { …
Sim
  • 13,147
  • 9
  • 66
  • 95
1
vote
1 answer

split a data frame with plyr

I found several question/answer on this topic, but I was not able to resolve my problem ... so I'll ask it my way. Sorry if it is obvious. I prepared a dataframe (z2) to use with ggplot2. This dataframe contains a column "value" with reals, a column…
jtextori
  • 239
  • 2
  • 7
1
vote
1 answer

How to use a multivariate function with ddply?

I'm trying to parse a multivariate function across a data.frame with ddply, in order to detect multivariate outliers per group. I expect to obtain a vector or an new column containing 1 (inliers) and 0 (outliers) using the the wfinal01 value of the…
essicolo
  • 803
  • 7
  • 13
1
vote
2 answers

R formula on a dataframe

I want to add the formulas I have used in a series of models to a data.frame require(plyr) require(nlme) str(baseball) ba <- baseball[1:100,] m01 <- gls( g ~ ab+I(r^2)+cos(pi*h),data=ba,correlation = corARMA(p=1)) m02 <- gls( g ~…
Leosar
  • 2,010
  • 4
  • 21
  • 32
1
vote
2 answers

R, Using reshape to pull pre post data

I have a simple data frame as follows x = data.frame(id = seq(1,10),val = seq(1,10)) x id val 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 I want to add 4 more columns. The first 2 are the previous two rows and the next two are…
broccoli
  • 4,738
  • 10
  • 42
  • 54
1
vote
1 answer

While reading multiple files into single data frame, create custom column for each of those files

Possible Duplicate: When importing CSV into R how to generate column with name of the CSV? I got a collection of files that I want to load into a single data frame. Each of the files I'm reading has the same structure, but different number of…
Geek On Acid
  • 6,330
  • 4
  • 44
  • 64
1
vote
1 answer

R- replace values in a matrix with the average value of its group?

I am new-ish to R and have what should be a simple enough question to answer; any help would be greatly appreciated. The situation is I have a tab delimited data matrix (data matrix.txt) like below with group information included on the last…
sinead
  • 269
  • 1
  • 4
  • 7
1
vote
2 answers

rbind.fill large data.frames

I am trying to rbind a large number of csv files that have many overlapping columns. library(plyr) filenames <- list.files("output/", pattern = "*.csv") filenames = paste("output/", filenames, sep="") frames =…
Rob Richmond
  • 855
  • 6
  • 19
1
vote
1 answer

R, Getting the top in every category from a data frame?

I have the following data frame id,category,value A,21,0.89 B,21,0.73 C,21,0.61 D,12,0.95 E,12,0.58 F,12,0.44 G,23,0.33 Note, they are already sorted by value within each (id,category). What I would like to be able to do is to get the top from each…
broccoli
  • 4,738
  • 10
  • 42
  • 54
1
vote
1 answer

Calculate increments of a variable in R

I have to calculate the increments of a variable m for a time interval (t2-t1). Here is a dummy version of my data frame: df <- expand.grid(m = do.breaks(c(1, 10), 5), sample = c("A", "B", "C", "D")) df$t <- rep(1:6, 4, ordered =…
matteo
  • 645
  • 3
  • 10
  • 18
1
vote
0 answers

Defining different functions with R based on ifelse cases; object of type 'closure' error

I'm modifying some previous code I got thanks to @BrianDiggs: []( Here's my reproducible code, as my actual code uses a data file and is much more involved based on various ifelse cases. This produces the same error: First, unmodified and…
Hendy
  • 10,182
  • 15
  • 65
  • 71
1
vote
2 answers

Apply a function over many shapefiles

I want to apply a function, either one that I have written, or one from a package such as the gArea function (e.g. gArea('shapefile')) from the rgeos package, across a list of shapefiles that I have imported. I imported the files like this: data <-…
Nick Crouch
  • 301
  • 3
  • 14
1
vote
1 answer

Issues with dcast function (reshape2) - three variable combination

I am using reshape2 package to shape my data and use it for t-test. For me it is easier to visualize the data in separate columns. I have three treatment combinations where "wat" is nested within "spp" and "ins" is nested within water. My demo table…
1
vote
2 answers

add data to a 3-d array using R

I have a series of functions in MATLAB that need to be converted into R. Unfortunately I do not know R all that well. A major hurdle is loading csv 100 files that are each 50x86069 into a 100, 50, 86069 array. I have the code set up to open/write…
1
vote
3 answers

Median of column and then look up other column value? (R)

I have this table: Profession Educational_level Number Doctor Low 0 Doctor Medium 5 Doctor High 8 Nurse Low 1 Nurse Medium 8 Nurse High 3 [...] I…
dani
  • 4,880
  • 8
  • 55
  • 95