Re: [R] Newbie: colSums() compared with Matlab's sum()

2009-12-23 Thread Francesco Napolitano
On Thu, Dec 24, 2009 at 4:38 AM, Brian G. Peterson wrote: > > data <- matrix(rnorm(100), nrow=10) # 10 x 10 > apply(data,2,cumsum) > > if you want to store the partial sums > (that was an important bit of information you left out) > > Thank you for your suggestion. However, I gave information onl

Re: [R] Newbie: colSums() compared with Matlab's sum()

2009-12-23 Thread Brian G. Peterson
Francesco Napolitano wrote: Il giorno mer, 23/12/2009 alle 22.14 -0500, David Winsemius ha scritto: for(i in 1:n){ submat <- data[1:i,] C <- colSums(submat) } In R the loop is not necessary, even confusing as you are demonstrating: > mat <- matrix(rnorm(100), nrow=10) # 10 x 10 >

Re: [R] Newbie: colSums() compared with Matlab's sum()

2009-12-23 Thread Francesco Napolitano
Il giorno mer, 23/12/2009 alle 22.14 -0500, David Winsemius ha scritto: > > for(i in 1:n){ > >submat <- data[1:i,] > >C <- colSums(submat) > >} > > > In R the loop is not necessary, even confusing as you are demonstrating: > > > mat <- matrix(rnorm(100), nrow=10) # 10 x 10 > > colSu

Re: [R] Newbie: colSums() compared with Matlab's sum()

2009-12-23 Thread Francesco Napolitano
So I see from help([[) what's happening: thank you very much. Il giorno mer, 23/12/2009 alle 18.59 -0800, Henrik Bengtsson ha scritto: > Use > >submat <- data[1:i,, drop=FALSE] > > /H > > On Wed, Dec 23, 2009 at 6:46 PM, Francesco Napolitano > wrote: > > Hi all, > > > > I'm trying to learn

Re: [R] Newbie: colSums() compared with Matlab's sum()

2009-12-23 Thread David Winsemius
On Dec 23, 2009, at 9:46 PM, Francesco Napolitano wrote: Hi all, I'm trying to learn R after years of Matlab's experience. Here is an issue I couldn't solve today. Consider the following piece of code (written by memory): for(i in 1:n){ submat <- data[1:i,] C <- colSums(submat) }

Re: [R] Newbie: colSums() compared with Matlab's sum()

2009-12-23 Thread Henrik Bengtsson
Use submat <- data[1:i,, drop=FALSE] /H On Wed, Dec 23, 2009 at 6:46 PM, Francesco Napolitano wrote: > Hi all, > > I'm trying to learn R after years of Matlab's experience. Here is an > issue I couldn't solve today. > > Consider the following piece of code (written by memory): > > for(i in 1

Re: [R] Newbie: colSums() compared with Matlab's sum()

2009-12-23 Thread Benilton Carvalho
replace data[1:i,] by data[1:i,drop=FALSE]. b On Dec 24, 2009, at 12:46 AM, Francesco Napolitano wrote: > Hi all, > > I'm trying to learn R after years of Matlab's experience. Here is an > issue I couldn't solve today. > > Consider the following piece of code (written by memory): > > for(i in

[R] Newbie: colSums() compared with Matlab's sum()

2009-12-23 Thread Francesco Napolitano
Hi all, I'm trying to learn R after years of Matlab's experience. Here is an issue I couldn't solve today. Consider the following piece of code (written by memory): for(i in 1:n){ submat <- data[1:i,] C <- colSums(submat) } The problem is that at the first iteration, data[1:1,] redu