Dear voidobscura, Try either: colSums(mdat) # or
apply(mdat, 2, sum) See ?colSums and ?apply for more details. HTH, Jorge On Thu, Jul 16, 2009 at 2:25 PM, voidobscura <nshah...@gmail.com> wrote: > > Alright, so I am trying to write my own function to calculate column sums > in > a matrix. I want the result as a single list with the values. > > So far I have: > > csum<-function(m) > { > a = data.frame(m) > s = lapply(a,sum) > return(s) > } > > What is the easiest way to have it return in a format such as [1] 6 15 24 ? > > Thanks. > -- > View this message in context: > http://www.nabble.com/DataFrame-help-tp24521881p24521881.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.