[R] options("contrasts")

(Ted Harding) Ted.Harding at manchester.ac.uk
Tue Aug 26 15:42:32 CEST 2008


On 26-Aug-08 10:30:30, David Epstein wrote:
> Code:
>> options("contrasts")
> $contrasts
>            factor           ordered 
> "contr.treatment"      "contr.poly"
> 
> I want to change the first entry ONLY, without retyping "contr.poly".
> How do I do it? I have tried various possibilities and cannot get
> anything to work.
> I found out that the response to options("contrasts") has class "list",
> but that doesn't help me, although I think it ought to help.
> 
> Second question (metaquestion). How should I go about finding out the
> answer to a question like "How does one change a single item in a
> list?"

In view of your meta-meta-strategy, here is a response to the
meta-question:

If you sijmply want to replace a given component (say $C) of
a list L, then use code like:

  L$C <- your.replacement

If you want to change the contents of a component of a list,
then what you need to do will depend on the nature of that
component (number, vector, array, anova table, list ... ).
Simple example:

  L<-list(A="A",B="B",C="Z",D="D")
  L
# $A
# [1] "A"
# $B
# [1] "B"
# $C
# [1] "Z"
# $D
# [1] "D"

  C<-L$C  ## extract $C from L
  C
# [1] "Z"
  C<-"C"  ## change it
  L$C<-C  ## put it back
  L
# $A
# [1] "A"
# $B
# [1] "B"
# $C
# [1] "C"
# $D
# [1] "D"

> My answer to the meta-meta-question is to post to this list.
> I hope that at least that part is correct.

It has been known to work ...
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 26-Aug-08                                       Time: 14:42:29
------------------------------ XFMail ------------------------------



More information about the R-help mailing list