[6335] in s-news-athena

home help back first fref pref prev next nref lref last post

matrix subset of data frame

daemon@ATHENA.MIT.EDU (garrett@gsc.emr.ca)
Tue Jan 31 17:55:23 1995

Date: Tue, 31 Jan 95 17:31:07 EST
From: garrett@gsc.emr.ca
To: s-news@utstat.toronto.edu

I have been spinning my wheels this afternoon trying to write a small function 
that generalizes the 3 lines noted below.  I routinely uses data.frames, but 
often need a matrix of a subset of the variables for all the cases to use in 
pairs, or similar functions:

> attach(dataframe)     # where data for var1, var2, etc. are stored
.
.
> elems <- c(var4, var2, var6, var9)
> mat <- matrix(elems, ncol = 4)
> dimnames(mat) <- list(NULL, c("var4", "var2", "var6", "var9"))

what I would like to have is a function that I can call, like:

> mat <- submatrix(c(var4, var2, var6, var9))
 or
> mat <- submatrix(c("var4", "var2", "var6", "var9"))

I have tried and failed, and looked in statlib and not seen anything that from 
the description does what I would like to do.

If anyone has faced and solved this problem I would appreciate the solution.

Thank you,

Robert G. (Bob) Garrett
Applied Geochemistry Subdivision
Geological Survey of Canada
601 Booth St., Ottawa, Ontario K1A 0E8
Internet: garrett@gsc.emr.ca
Tel.: 613+995-4517   FAX: 613+996-3726

home help back first fref pref prev next nref lref last post