Dear voidobscura,
Try also
Csum <- function(x) apply(x, 2, sum)
Csum(m)
HTH,
Jorge
On Mon, Jul 27, 2009 at 11:03 AM, voidobscura <> wrote:
>
> Hi all, I have been experimenting with writing my own matrix column sum
> function. I want it to return a list.
>
> csum<-function(m)
> {
>a = da
All you need is
csum <- function(m) sapply(m, sum)
(in which case making csum a function does not achieve very much).
If for some reason you want to hang on to your code and just modify the last
line (though I cannot think why, but still...) you could do
csum <- function(m) {
a <- data.fr
Hi voidobscura,
Try either
csum2 <- function(m){
a = data.frame(m)
s = lapply(a,sum)
do.call(c, s)
}
or
colSums(m)
See ?do.call and ?colSums for more details.
HTH,
Jorge
On Mon, Jul 27, 2009 at 11:03 AM, voidobscura wrote:
>
> Hi all, I have been experimenting with writing my own
have a look at ?unlist(); you can also use sapply() in this case instead
of lapply().
Best,
Dimitris
voidobscura wrote:
Hi all, I have been experimenting with writing my own matrix column sum
function. I want it to return a list.
csum<-function(m)
{
a = data.frame(m)
s = lapply(a,s
4 matches
Mail list logo