[R] How to add rowSums into list?

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Fri Jan 11 14:17:37 CET 2008


a <- list(one=matrix(rnorm(20), 5, 4), two=matrix(rnorm(20, 3,
0.5),5,4))

lapply(a, function(x){
  cbind(x, rowSums(x))
})

Cheers,

Thierry 


------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be 
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
Namens Lauri Nikkinen
Verzonden: vrijdag 11 januari 2008 14:09
Aan: r-help at stat.math.ethz.ch
Onderwerp: [R] How to add rowSums into list?

Hi R-users,

I have a list

a <- list(one=matrix(rnorm(20), 5, 4), two=matrix(rnorm(20, 3,
0.5),5,4))

How to add rowSums (calculated using lapply) to corresponding matrix
in this list

lapply(a, function(x) rowSums(x))

??

-Lauri

______________________________________________
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.




More information about the R-help mailing list