[R] Lattice bwplot(): Conditioning on one factor

David Winsemius dwinsemius at comcast.net
Fri Sep 28 19:10:56 CEST 2012


On Sep 28, 2012, at 9:56 AM, Rich Shepard wrote:

> On Fri, 28 Sep 2012, David Winsemius wrote:
> 
>> Wouldn't that involve specifying the 'subset' parameter (if bwplot accepts
>> a subset argument) or using the 'subset' function to pass the desired rows
>> to the data argument if it doesn't?
> 
> David,
> 
>  That's what I tried:
> 
>>> bwplot(quant ~ param | era, data=mg.d, main='Magnesium', ylab='Concentration
>>> (mg/L)', subset=era('Pre-mining'))

Sigh. If I were testing that strategy (which I did not try because you were too busy to have included a working example)  I would have written it:

bwplot(quant ~ param , data=mg.d, main='Magnesium', ylab='Concentration
(mg/L)', subset= era=='Pre-mining' )

That passes a logical vector which will "work" only if bwplot created an local environment where column names of the 'data' argument have been added to the local namespce. I do not know if that is true. I just looked at the bwplot help page and do not see a subset argument documented there.

The other suggestion which it seems you were also to busy too have tried was:

bwplot(quant ~ param ,  main='Magnesium', ylab='Concentration
(mg/L)', data = subset( mg.dsubset,  era=='Pre-mining' ) )

Wrapping a column name around a factor level with parentheses (which R takes to mean there is a function named 'era' to be applied)  and expecting R to understand the you want a subset seems doomed to failure.

It makes no sense to me to condition on a factor that you know for certainty has only one level in the data being offered.
--

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list