[R] how to fix a factor

Andrew Robinson andrewr at uidaho.edu
Fri Mar 19 18:04:21 CET 2004


Giampiero,

It's certainly possible.  

Many commands allow the "subset" option, which permits the analysis of only a 
portion of a dataframe, although boxplot does not.  

Also, you could preface your analysis with a logical condition, like 

my sample <- x3 == 1
boxplot(y[my sample] ~ x1[my sample] + x2[my sample])

You can wrap the preceding code in a for loop to apply it to each level of the 
factor.

Frank Harrell's useful mapply() will allow you to vectorize over more than one 
argument.  Look for it in the package Hmisc on CRAN.

Andrew

On Friday 19 March 2004 08:31, Giampiero Salvi wrote:
> Hi all,
> I created a data frame with three factors, plus the response that
> looks like this:
>
> x1	x2	x3	y
> a	1	1	0.3
> a	2	1	0.1
> b	1	1	0.4
> c	4	3	0.1
> ...
>
> I would like to analise the effect of two of them, keeping the third fixed
> (I already know the effect of the last). The reason why I don't create
> several data frames for each value of the thirs factor is simply
> convenience (I'd like to be able to decide which factor I want to rule out)
>
> for example I'd like to write something like
>
> boxplot(y ~ x1 + x2, x3 == 1)
>
> which of course doesn't work, otherwise I wouldn't write :-)
>
> Is this possible and how?
>
> Thank you
> Giampiero
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

-- 
Andrew Robinson                      Ph: 208 885 7115
Department of Forest Resources       Fa: 208 885 6226
University of Idaho                  E : andrewr at uidaho.edu
PO Box 441133                        W : http://www.uidaho.edu/~andrewr
Moscow ID 83843                      Or: http://www.biometrics.uidaho.edu
No statement above necessarily represents my employer's opinion.




More information about the R-help mailing list