Re: [R] matrix help (first occurrence of variable in column)

2011-05-19 Thread jim holtman
Is this what you are looking for: > mdat3 sp.1 sp.2 sp.3 sp.4 sp.5 T110010 T210010 T311100 T410111 > > # create a matrix of when species first appeared > first <- apply(mdat3, 2, function(x) (cumsum(x == 1) > 0) + 0

Re: [R] matrix help (first occurrence of variable in column)

2011-05-19 Thread Michael Denslow
On Wed, May 18, 2011 at 9:49 PM, jim holtman wrote: > Is this what you were after: > >> mdat <- matrix(c(1,0,1,1,1,0), nrow = 2, ncol=3, byrow=TRUE, > +               dimnames = list(c("T1", "T2"), > +                               c("sp.1", "sp.2", "sp.3"))) >> >> mdat >   sp.1 sp.2 sp.3 > T1    

Re: [R] matrix help (first occurrence of variable in column)

2011-05-18 Thread jim holtman
Is this what you were after: > mdat <- matrix(c(1,0,1,1,1,0), nrow = 2, ncol=3, byrow=TRUE, + dimnames = list(c("T1", "T2"), + c("sp.1", "sp.2", "sp.3"))) > > mdat sp.1 sp.2 sp.3 T1101 T2110 > # do 'rle' on each column and see

Re: [R] Matrix Help

2011-02-20 Thread Mark Knecht
On Sun, Feb 20, 2011 at 2:56 PM, Dmitry Berman wrote: > On Sun, Feb 20, 2011 at 5:55 PM, Dmitry Berman wrote: > >> Listers, >> >> I have a simple matrix: >> >> -- >> m <-c(1:7) >> m <- cbind(m) >> >> m >> [1,] 1 >> [2,] 2 >> [3,] 3 >> [4,] 4 >> [5,] 5 >> [6,] 6 >>

Re: [R] Matrix Help

2011-02-20 Thread David Winsemius
On Feb 20, 2011, at 5:56 PM, Dmitry Berman wrote: On Sun, Feb 20, 2011 at 5:55 PM, Dmitry Berman wrote: Listers, I have a simple matrix: -- m <-c(1:7) m <- cbind(m) m [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 --- I

Re: [R] Matrix Help

2011-02-20 Thread Dmitry Berman
On Sun, Feb 20, 2011 at 5:55 PM, Dmitry Berman wrote: > Listers, > > I have a simple matrix: > > -- > m <-c(1:7) > m <- cbind(m) > > m > [1,] 1 > [2,] 2 > [3,] 3 > [4,] 4 > [5,] 5 > [6,] 6 > [7,] 7 > --- > > I want to add a second co

Re: [R] matrix help

2010-09-26 Thread Remko Duursma
I think you want ?solve ... Remko -- View this message in context: http://r.789695.n4.nabble.com/matrix-help-tp2714378p2714896.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/ma