[R] Extracting objects from a list of matrix

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Sep 19 09:08:00 CEST 2003


ZABALZA-MEZGHANI Isabelle wrote:

> Hello,
> 
> I would like to have an advise about how to extract objects from a list of
> matrixs
> I have fitted models (stored in an object called "model") using a matrix
> response and the same formula and data. I get back, from summary.lm, as many
> sumarries as I have responses.
> Thus I have extract the coefficient matrix for each model with the following
> command :
> 
> coefficients(summary(model))
> 
> My goal is only to get the "t values" for each model. Generally to extract a
> colum from a matrix I do [,"t value"], and to apply a function to a list I
> use lapply. But here, I can not manage to extract the columns, since the
> "[]" function, is not really a function with arguments ...

Why not? Try e.g.:

X <- matrix(1:4, 2)
"["(X,,2)

So in order to solve your problem try:

  lapply(YourList, "[", , "t-value")

or use an anonymous function:

  lapply(YourList, function(x) x[, "t-value"])


Uwe Ligges



> Can someone give me a solution ? (in avoiding to make a loop around my list
> components).
> 
> Thanks in advance,
> 
> Isabelle.
> 
> 
> Isabelle Zabalza-Mezghani
> IFP - Reservoir Engineering Department
> Rueil-Malmaison - France
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help



lapply(....., function(x) x[,"t value"])




More information about the R-help mailing list