[R] as.character and a formula

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Aug 16 20:22:08 CEST 2005


Gavin Simpson wrote:

> Dear list,
> 
> given this formula: 
> 
> 
>>fmla <- formula(y1 ~ spp1 + spp2 + spp3 + spp5)
>>fmla[[3]]
> 
> spp1 + spp2 + spp3 + spp5
> 
> is this the intended behaviour of as.character:
> 
> 
>>as.character(fmla[[3]])
> 
> [1] "+"                  "spp1 + spp2 + spp3" "spp5"
> 
> ? Where does the extra "+" come from?

Which *extra* "+"?

This expression is the same as

"+"(spp1 + spp2 + spp3, spp5)

hence "+" with arguments "spp1 + spp2 + spp3" and "spp5"

Same below.

Uwe Ligges


> 
>>as.character(fmla)
> 
> [1] "~"                         "y1"                       
> [3] "spp1 + spp2 + spp3 + spp5"
> 
> Thanks in advance,
> 
> Gav




More information about the R-help mailing list