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

Bert Gunter gunter.berton at gene.com
Fri Sep 28 19:31:16 CEST 2012


Yes. Now I understand what was wanted.

1. the subset argument is certainly documented on the Help page:

subset 	

An expression that evaluates to a logical or integer indexing vector.
Like groups, it is evaluated in data. Only the resulting rows of data
are used for the plot. If subscripts is TRUE, the subscripts provided
to the panel function will be indices referring to the rows of data
prior to the subsetting. Whether levels of factors in the data frame
that are unused after the subsetting will be dropped depends on the
drop.unused.levels argument.

Had the OP read this carefully, he would have presumably recognized
the errors in his specification.

2. Here is a small reproducible example to show how it should be done
(probably unnecessary now):

> df <-expand.grid(a = letters[1:3],b=LETTERS[1:2])
> df <- df[rep(1:6,10),]
> df$y <- runif(60)
> bwplot(y~a|b, dat=df,subset = (b=="A"))
## The logical condition is parenthesized only for clarity

Cheers,
Bert



On Fri, Sep 28, 2012 at 10:10 AM, David Winsemius
<dwinsemius at comcast.net> wrote:
>
> 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
>
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm




More information about the R-help mailing list