Re: [R] How to sum only a few elements in a line

2009-11-25 Thread David Winsemius
On Nov 25, 2009, at 3:45 PM, William Dunlap wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Marcio Resende Sent: Wednesday, November 25, 2009 12:27 PM To: r-help@r-project.org Subject: [R] How to sum only a few elements in

Re: [R] How to sum only a few elements in a line

2009-11-25 Thread Peter Ehlers
Marcio Resende wrote: Hello, I have a matrix with the numbers 0,1 and 9 I would like to write a function that could sum each line skiping everytime a number 9 appears for example [0 1 0 1 1 9 1] the sum would be 4. However I cannot replace 9 by 0 otherwise after the sum is done I wouldn´t be a

Re: [R] How to sum only a few elements in a line

2009-11-25 Thread David Winsemius
On Nov 25, 2009, at 3:27 PM, Marcio Resende wrote: Hello, I have a matrix with the numbers 0,1 and 9 I would like to write a function that could sum each line skiping everytime a number 9 appears for example [0 1 0 1 1 9 1] sum(x[x != 9]) the sum would be 4. However I cannot replace 9

Re: [R] How to sum only a few elements in a line

2009-11-25 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Marcio Resende > Sent: Wednesday, November 25, 2009 12:27 PM > To: r-help@r-project.org > Subject: [R] How to sum only a few elements in a line > >

Re: [R] How to sum only a few elements in a line

2009-11-25 Thread Peter Alspach
er 2009 9:27 a.m. > To: r-help@r-project.org > Subject: [R] How to sum only a few elements in a line > > > Hello, > > I have a matrix with the numbers 0,1 and 9 I would like to > write a function that could sum each line skiping everytime a > number 9 appears for exa

[R] How to sum only a few elements in a line

2009-11-25 Thread Marcio Resende
Hello, I have a matrix with the numbers 0,1 and 9 I would like to write a function that could sum each line skiping everytime a number 9 appears for example [0 1 0 1 1 9 1] the sum would be 4. However I cannot replace 9 by 0 otherwise after the sum is done I wouldn´t be able to distiguish which o