[R] 2D array of strings

2009-12-28 Thread Francesco Napolitano
Sorry for the dumb question, but I couldn't figure this out myself. Consider the following: > str <- c("abc","def") > array(str, c(2,1)) [,1] [1,] "abc" [2,] "def" How can i obtain the outcome of the second instruction without specifying the number of rows? Thank you in advance, Francesco.

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 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: &

[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