ZABALZA-MEZGHANI Isabelle
2003-Sep-19 06:43 UTC
[R] Extracting objects from a list of matrix
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 ... 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
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-helplapply(....., function(x) x[,"t value"])
kjetil brinchmann halvorsen
2003-Sep-20 14:11 UTC
[R] Extracting objects from a list of matrix
On 19 Sep 2003 at 8:43, ZABALZA-MEZGHANI Isabelle wrote: [ is a function:> test <- list(a=1, b=2, c=3) > "["(test,2)$b [1] 2 Kjetil Halvorsen> 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 ... > > 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