[R] only actual variable names in all.names()

Henrique Dallazuanna wwwhsd at gmail.com
Thu Mar 4 14:49:54 CET 2010


Try this:

all.vars(substitute(y ~ poly(x, k) + z, list(k = NA)))

Or if you don't want substitute the var k:

gsub(".*\\((.*),.*", "\\1", rownames(attr(terms(y ~ poly(x, k) + z),
'factors')))


On Thu, Mar 4, 2010 at 6:57 AM, Vito Muggeo (UniPa)
<vito.muggeo at unipa.it> wrote:
> dear all,
> When I use all.vars(), I am interest in extracting only the variable names..
> Here a simple example
>
> all.vars(as.formula(y~poly(x,k)+z))
>
> returns
> [1] "y" "x" "k" "z"
>
> and I would like to obtain
> "y" "x" "z"
>
> Where is the trick?
>
> many thanks
> vito
>
>
> --
> ====================================
> Vito M.R. Muggeo
> Dip.to Sc Statist e Matem `Vianelli'
> Università di Palermo
> viale delle Scienze, edificio 13
> 90128 Palermo - ITALY
> tel: 091 23895240
> fax: 091 485726/485612
> http://dssm.unipa.it/vmuggeo
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list