[R] Summary: extracting the names of the dataframe and variables

John Miyamoto jmiyamot at u.washington.edu
Mon Mar 24 02:19:04 CET 2003


Dear R Help,
   Thanks to Spencer Graves and Yusuke Miyamoto for suggestions.  The
original question was how to extract the name of the data set and variable
names from an lm or aov output object.  The following function based on
their suggestions does the trick.

v.names <- function(lm.out, data.name=NA) {
	X <- names(lm.out$model)
	Y <- c(as.character(lm.out$call$data), X)
	names(Y) <- c("data", "dep.var",
		paste("var", 1:(length(X) - 1), sep=""))
	Y
	}  #end of v.names function definition

tst.dat <- data.frame(Vis=rep(c(-1, 1), 8),
        Cmplx=rep(rep(c(-1,1), each=2), 4),
	Isi=rep(rep(c(-1,1), each=4), 2),
        Rt=rnorm(16))

tst.fit <- lm(Rt ~ Vis*Cmplx*Isi, data=tst.dat)

v.names(tst.fit)
     data   dep.var      var1      var2      var3
"tst.dat"      "Rt"     "Vis"   "Cmplx"     "Isi"

Thank you,

John Miyamoto

--------------------------------------------------------------------
John Miyamoto, Dept. of Psychology, Box 351525
University of Washington, Seattle, WA 98195-1525
Phone 206-543-0805, Fax 206-685-3157, Email jmiyamot at u.washington.edu
Homepage http://faculty.washington.edu/jmiyamot/
--------------------------------------------------------------------



More information about the R-help mailing list