[R] subset() missing one factor
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Wed Dec 28 19:24:58 CET 2011
Might I suggest looking in chemdata? You have supplied sample records from your original data file, but the transition from that to your result is still opaque. Try to generate a reproducible sequence of steps starting with your data that we can follow along with.
Comment: you keep saying that the dates are not selected, but dates are not the only info missing; there are no records at all in the result.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Rich Shepard <rshepard at appl-ecosys.com> wrote:
> 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
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list