Re: [R] First value in a row

2012-07-25 Thread arun
. - Original Message - From: Camilo Mora cm...@dal.ca To: r-help@r-project.org Cc: Sent: Tuesday, July 24, 2012 2:48 AM Subject: [R] First value in a row Hi. This is likely a trivial problem but have not found a solution. Imagine the following dataframe: Lat   Lon  x1   x2

Re: [R] First value in a row

2012-07-25 Thread arun
, 2012 2:48 AM Subject: [R] First value in a row Hi. This is likely a trivial problem but have not found a solution. Imagine the following dataframe: Lat   Lon  x1   x2  x3 01    10   NA   NA  .1 01    11   NA   .2  .3 01    12   .4   .5  .6 I want to generate another column

Re: [R] First value in a row

2012-07-25 Thread arun
Mora cm...@dal.ca To: r-help@r-project.org Cc: Sent: Tuesday, July 24, 2012 2:48 AM Subject: [R] First value in a row Hi. This is likely a trivial problem but have not found a solution. Imagine the following dataframe: Lat   Lon  x1   x2  x3 01    10   NA   NA  .1 01    11   NA   .2

Re: [R] First value in a row

2012-07-25 Thread arun
...@dal.ca To: r-help@r-project.org Cc: Sent: Tuesday, July 24, 2012 2:48 AM Subject: [R] First value in a row Hi. This is likely a trivial problem but have not found a solution. Imagine the following dataframe: Lat   Lon  x1   x2  x3 01    10   NA   NA  .1 01    11   NA   .2  .3 01

[R] First value in a row

2012-07-24 Thread Camilo Mora
Hi. This is likely a trivial problem but have not found a solution. Imagine the following dataframe: Lat Lon x1 x2 x3 0110 NA NA .1 0111 NA .2 .3 0112 .4 .5 .6 I want to generate another column that consist of the first value in each row from columns x1 to

Re: [R] First value in a row

2012-07-24 Thread Henrik Singmann
Hi Camilo, as you want to work on all rows, apply() is your friend. In the following, I use an anonymous function getting the first non-na value while looping over each row: dat - read.table(text = Lat Lon x1 x2 x3 0110 NA NA .1 0111 NA .2 .3 0112 .4 .5 .6 ,

Re: [R] First value in a row

2012-07-24 Thread arun
  x3 NewColumn 1   1  10  NA  NA 0.1   0.1 2   1  11  NA 0.2 0.3   0.2 3   1  12 0.4 0.5 0.6   0.4 A.K. - Original Message - From: Camilo Mora cm...@dal.ca To: r-help@r-project.org Cc: Sent: Tuesday, July 24, 2012 2:48 AM Subject: [R] First value in a row Hi

Re: [R] First value in a row

2012-07-24 Thread Henrik Singmann
-project.org Cc: Sent: Tuesday, July 24, 2012 2:48 AM Subject: [R] First value in a row Hi. This is likely a trivial problem but have not found a solution. Imagine the following dataframe: Lat Lon x1 x2 x3 0110 NA NA .1 0111 NA .2 .3 0112 .4 .5 .6 I want to generate

Re: [R] First value in a row

2012-07-24 Thread William Dunlap
Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Henrik Singmann Sent: Tuesday, July 24, 2012 1:40 AM To: r-h...@stat.math.ethz.ch Subject: Re: [R] First value in a row Hi Camilo, as you want to work on all rows, apply() is your friend

Re: [R] First value in a row

2012-07-24 Thread arun
  NA 0.1      0.1 2  1  11  NA 0.2 0.3      0.2 3  1  12 0.4 0.5 0.6      0.4 A.K. - Original Message - From: Camilo Mora cm...@dal.ca To: r-help@r-project.org Cc: Sent: Tuesday, July 24, 2012 2:48 AM Subject: [R] First value in a row Hi. This is likely a trivial problem

Re: [R] First value in a row

2012-07-24 Thread Camilo Mora
0.4 0.5 0.6      0.4 A.K. - Original Message - From: Camilo Mora cm...@dal.ca To: r-help@r-project.org Cc: Sent: Tuesday, July 24, 2012 2:48 AM Subject: [R] First value in a row Hi. This is likely a trivial problem but have not found a solution. Imagine the following dataframe

Re: [R] First value in a row

2012-07-24 Thread Tyler Rinker
. - Original Message - From: Camilo Mora cm...@dal.ca To: r-help@r-project.org Cc: Sent: Tuesday, July 24, 2012 2:48 AM Subject: [R] First value in a row Hi. This is likely a trivial problem but have not found a solution. Imagine the following dataframe: Lat Lon x1

[R] first value...

2009-06-23 Thread Alfredo Alessandrini
Hi, I've a vector like this: inc [1]NANANANANANANA [8]NANANANANANANA [15]NANANANANANANA [22]NANA

Re: [R] first value...

2009-06-23 Thread Henrique Dallazuanna
Try this: which(diff(is.na(inc)) 0) On Tue, Jun 23, 2009 at 11:00 AM, Alfredo Alessandrini alfreal...@gmail.com wrote: Hi, I've a vector like this: inc [1]NANANANANANANA [8]NANANANANA

Re: [R] first value...

2009-06-23 Thread Alfredo Alessandrini
Now is ok...thanks. Alfredo 2009/6/23 Alfredo Alessandrini alfreal...@gmail.com: I've the NA value also between the value of the vector: inc  [1]        NA        NA        NA        NA        NA        NA        NA  [8]        NA        NA        NA        NA        NA        NA        NA

Re: [R] first value...

2009-06-23 Thread David Winsemius
On Jun 23, 2009, at 10:00 AM, Alfredo Alessandrini wrote: Hi, I've a vector like this: inc [1]NANANANANA NANA [8]NANANANANA NANA [15]NANANANA

Re: [R] first value...

2009-06-23 Thread Alfredo Alessandrini
I've the NA value also between the value of the vector: inc [1]NANANANANANANA [8]NANANANANANANA [15]NANANANANANANA [22]

Re: [R] first value...

2009-06-23 Thread Wacek Kusnierczyk
Alfredo Alessandrini wrote: Hi, I've a vector like this: inc [1]NANANANANANANA [8]NANANANANANANA [15]NANANANANANA

Re: [R] first value...

2009-06-23 Thread Philipp Pagel
On Tue, Jun 23, 2009 at 04:00:21PM +0200, Alfredo Alessandrini wrote: I've a vector like this: inc [1]NANANANANANANA [8]NANANANANANANA [15]NANANA

Re: [R] first value...

2009-06-23 Thread Daniel Malter
Alfredo Alessandrini Gesendet: Tuesday, June 23, 2009 10:00 AM An: r-help@r-project.org Betreff: [R] first value... Hi, I've a vector like this: inc [1]NANANANANANANA [8]NANANANANANA

Re: [R] first value...

2009-06-23 Thread Henrique Dallazuanna
You can use this: inc[which(!is.na(inc))[1]] On Tue, Jun 23, 2009 at 11:08 AM, Alfredo Alessandrini alfreal...@gmail.com wrote: I've the NA value also between the value of the vector: inc [1]NANANANANANANA [8]NANA

Re: [R] first value...

2009-06-23 Thread Stavros Macrakis
I think what you mean is that you want to find the position of the first non-NA value in the vector. is.na returns a boolean vector of the NA values, so: xx - c(NA,NA,NA,2,3,NA,4) which(!is.na(xx))[1] [1] 4 The other proposed solution, which(diff(is.na(inc)) 0) is incorrect:

Re: [R] first value...

2009-06-23 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 23.06.2009 16:04:49: Try this: which(diff(is.na(inc)) 0) Shall it be which(diff(is.na(inc)) 0)+1 or sum(is.na(inc))+1 or any other suitable construct with is.na Regards Petr On Tue, Jun 23, 2009 at 11:00 AM, Alfredo Alessandrini

Re: [R] first value...

2009-06-23 Thread Carl Witthoft
The various which(is.na) sort of things are fine, but this problem is just screaming to be solved with rle(). Just do rle(is.na(inc))$lengths[1]+1 On Tue, Jun 23, 2009 at 11:00 AM, Alfredo Alessandrini alfreale74 at gmail.com wrote: Hi, I've a vector like this: inc [1]