[R] What is "assign" attribute?

rkevinburton at charter.net rkevinburton at charter.net
Thu Mar 4 15:41:54 CET 2010


I am sorry I still don't understand.

In the example you give the 'assign' vecotr is a vector of length 6 and there are indeed 6 columns in the data frame. But the formula only has two variables namely 'Month' and 'Wind'. Where do the values if the 'assign' vector come from? I see '0 1 1 1 1 2'. What is '1' an index to? '2'? Maybe I am get confused with what the term 'factors' does to the formula.

Thanks agiain for your help.

Kevin

---- Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote: 
> rkevinburton at charter.net wrote:
> > I am just curious. Every once and a while I see an attribute attached to an object called "assign". What meaning does this have? For example:
> > 
> > dist ~ speed, data=cars
> > 
> > forms a matrix like:
> > 
> >  num [1:50, 1:2] 1 1 1 1 1 1 1 1 1 1 ...
> >  - attr(*, "dimnames")=List of 2
> >   ..$ : chr [1:50] "1" "2" "3" "4" ...
> >   ..$ : chr [1:2] "(Intercept)" "speed"
> >  - attr(*, "assign")= int [1:2] 0 1
> > 
> > The "dimnames" attribute is fairly self-explanatory. I just am not sure what the "assign" attribute means.
> 
> It has to do with the mapping between terms of the formula and columns 
> of the design matrix:
> 
>  > str(model.matrix(Ozone~factor(Month)+Wind,data=airquality))
>   num [1:116, 1:6] 1 1 1 1 1 1 1 1 1 1 ...
>   - attr(*, "dimnames")=List of 2
>    ..$ : chr [1:116] "1" "2" "3" "4" ...
>    ..$ : chr [1:6] "(Intercept)" "factor(Month)6" "factor(Month)7" 
> "factor(Month)8" ...
>   - attr(*, "assign")= int [1:6] 0 1 1 1 1 2
>   - attr(*, "contrasts")=List of 1
>    ..$ factor(Month): chr "contr.treatment"
> 
> I.e. columns 2:5 belong to the first non-intercept term, factor(Month). 
> (Notice that it is implicitly assumed that you have the corresponding 
> terms() output to hand, likewise for the "contrasts" attribute.)
> -- 
>     O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
>    c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
>   (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list