Re: [R] optimal way to compute matrix subtotals?

2006-05-14 Thread Werner Wernersen
Thank you all for your replys!

It is so much faster with rowsum(), thanks a million!
  Werner

Dimitris Rizopoulos [EMAIL PROTECTED] schrieb: probably you want ?rowsum(); I 
hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: Werner Wernersen 

To: 
Sent: Friday, May 12, 2006 11:48 AM
Subject: [R] optimal way to compute matrix subtotals?


 Hi!

 I have large matrices, one column per variable and I have a vector 
 of factors / grouping symbols. Then I am computing subtotals for the 
 groups but it takes pretty long and thus I wanted to ask if there is 
 a better way to do it or if this is already the best way:
 subTotals - function(x, groupvec) 
 do.call(rbind,lapply(split(x,groupvec),colSums,na.rm=T))


 Thanks reading my question and any hints!
 Werner


 -

 [[alternative HTML version deleted]]

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm





-


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] optimal way to compute matrix subtotals?

2006-05-12 Thread Werner Wernersen
Hi!

I have large matrices, one column per variable and I have a vector of factors / 
grouping symbols. Then I am computing subtotals for the groups but it takes 
pretty long and thus I wanted to ask if there is a better way to do it or if 
this is already the best way:
subTotals - function(x, groupvec) 
do.call(rbind,lapply(split(x,groupvec),colSums,na.rm=T))


Thanks reading my question and any hints!
 Werner


-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] optimal way to compute matrix subtotals?

2006-05-12 Thread Prof Brian Ripley
On Fri, 12 May 2006, Werner Wernersen wrote:

 Hi!

 I have large matrices, one column per variable and I have a vector of 
 factors / grouping symbols. Then I am computing subtotals for the groups 
 but it takes pretty long and thus I wanted to ask if there is a better 
 way to do it or if this is already the best way: subTotals - 
 function(x, groupvec) 
 do.call(rbind,lapply(split(x,groupvec),colSums,na.rm=T))

I suggest you look at rowsum (on a transpose of your matrix).  It will not 
handle NAs, though, if you have any.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] optimal way to compute matrix subtotals?

2006-05-12 Thread Petr Pikal
Hi

not sure about speed but aggregate can probably do it.

aggregate(x, list(groupvec), sum, na.rm=T)

HTH
Petr



On 12 May 2006 at 11:48, Werner Wernersen wrote:

Date sent:  Fri, 12 May 2006 11:48:45 +0200 (CEST)
From:   Werner Wernersen [EMAIL PROTECTED]
To: r-help@stat.math.ethz.ch
Subject:[R] optimal way to compute matrix subtotals?

 Hi!
 
 I have large matrices, one column per variable and I have a vector of
 factors / grouping symbols. Then I am computing subtotals for the
 groups but it takes pretty long and thus I wanted to ask if there is a
 better way to do it or if this is already the best way: subTotals -
 function(x, groupvec)
 do.call(rbind,lapply(split(x,groupvec),colSums,na.rm=T))
 
 
 Thanks reading my question and any hints!
  Werner
 
 
 -
 
  [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html

Petr Pikal
[EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] optimal way to compute matrix subtotals?

2006-05-12 Thread Dimitris Rizopoulos
probably you want ?rowsum(); I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: Werner Wernersen [EMAIL PROTECTED]
To: r-help@stat.math.ethz.ch
Sent: Friday, May 12, 2006 11:48 AM
Subject: [R] optimal way to compute matrix subtotals?


 Hi!

 I have large matrices, one column per variable and I have a vector 
 of factors / grouping symbols. Then I am computing subtotals for the 
 groups but it takes pretty long and thus I wanted to ask if there is 
 a better way to do it or if this is already the best way:
 subTotals - function(x, groupvec) 
 do.call(rbind,lapply(split(x,groupvec),colSums,na.rm=T))


 Thanks reading my question and any hints!
 Werner


 -

 [[alternative HTML version deleted]]

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html