[R] subset() missing one factor

Rich Shepard rshepard at appl-ecosys.com
Wed Dec 28 19:03:23 CET 2011


   The data set (called 'chemdata') has 6 columns (4 factors, 1 date, 1
numeric) and I need to create subsets for each of one of the factors
('stream'). This has worked flawlessly for all but two streams which were
created yesterday.

   The command I use to create the subsets is like this:

> rnchH <- subset(chemdata, stream == 'RanchSpgsH', select = c(site, sampdate,
param, quant), drop = T)

but it does not copy the dates in 'sampdate' for this and one other subset:

> str(rnchH)
'data.frame':	0 obs. of  4 variables:
  $ site    : Factor w/ 138 levels "BC-0.5","BC-1",..:
  $ sampdate:Class 'Date'  num(0)
  $ param   : Factor w/ 58 levels "AGP","ANP","ANP/AGP",..:
  $ quant   : num

   The source for chemdata (accessed by read.table()) has dates for this
stream; e.g.,

RNCHS|1994-03-23|pH|7.66|RanchSpgsH|H
RNCHS|1994-01-20|pH|7.66|RanchSpgsH|H

   If I use the same command on a different stream the sampdate column
contains the dates:

> b2 <- subset(chemdata, stream == 'BurnsCrk', select = c(site, sampdate,
param, quant), drop = T)
> str(b2)
'data.frame':	2472 obs. of  4 variables:
  $ site    : Factor w/ 138 levels "BC-0.5","BC-1",..: 5 5 5 5 5 5 5 5 5 ...
  $ sampdate: Date, format: "1992-03-27" "1992-04-30" ...
  $ param   : Factor w/ 58 levels "AGP","ANP","ANP/AGP",..: 37 37 37 37 ...
  $ quant   : num  0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 8.08 ...

   I keep looking to see why the first fails but have not found it. Pointers
on where to look will be helpful.

TIA,

Rich



More information about the R-help mailing list