Skip to content

Removal/selecting specific rows in a dataframe conditional on 2 columns

3 messages · Aurelie Cosandey Godin, R. Michael Weylandt, Dennis Murphy

#
Perhaps use tapply() to split by the survey unit and write a little
identity function that returns only those rows you want, then patch
them all back together with something like simplify2array().

Michael
On Tue, Nov 1, 2011 at 1:16 PM, Aurelie Cosandey Godin <godina at dal.ca> wrote:
#
Does this work?

library('plyr')
# Function to return a data frame if it has one row, else return NULL:
f <- function(d) if(nrow(d) == 1L) d else NULL
record.t trip set month stratum NAFO unit.area time dur.set distance
1        5  913   1    10     351   3O       R31 1044      17        9
2        5  913   3    10     340   3O       Q31 1800      18        9
3        5  913   4    10     340   3O       Q32 2142      17        9

ddply() is an apply-like function that takes a data frame as input and
a data frame as output (hence the dd). The first argument is the data
frame name, the second argument the set of grouping variables and the
third is the function to be called (in this application).

HTH,
Dennis
On Tue, Nov 1, 2011 at 10:16 AM, Aurelie Cosandey Godin <godina at dal.ca> wrote: