[R] how to select the first observation only?

2010-04-21 Thread gallon li
Dear r-helpers, I have a very simple question. Suppose my data is like id=c(rep(1,2),rep(2,2)) b=c(2,3,4,5) m=cbind(id,b) m id b [1,] 1 2 [2,] 1 3 [3,] 2 4 [4,] 2 5 I wish to select the first observation for each id. That is, I want to quickly select two rows: id b 1 2 2 4 only. how

Re: [R] how to select the first observation only?

2010-04-21 Thread Thomas Stewart
Try the duplicated() function. As in m[!duplicated(id), ] -tgs On Wed, Apr 21, 2010 at 10:17 PM, gallon li gallon...@gmail.com wrote: Dear r-helpers, I have a very simple question. Suppose my data is like id=c(rep(1,2),rep(2,2)) b=c(2,3,4,5) m=cbind(id,b) m id b [1,] 1 2

Re: [R] how to select the first observation only?

2010-04-21 Thread Daniel Malter
discussurus - -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of gallon li Sent: Wednesday, April 21, 2010 10:18 PM To: r-help Subject: [R] how to select the first observation only? Dear r-helpers, I have a very simple

Re: [R] how to select the first observation only?

2010-04-21 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of gallon li Sent: Wednesday, April 21, 2010 7:18 PM To: r-help Subject: [R] how to select the first observation only? Dear r-helpers, I have a very simple question. Suppose

Re: [R] how to select the first observation only?

2010-04-21 Thread David Winsemius
On Apr 21, 2010, at 10:17 PM, gallon li wrote: Dear r-helpers, I have a very simple question. Suppose my data is like id=c(rep(1,2),rep(2,2)) b=c(2,3,4,5) m=cbind(id,b) m id b [1,] 1 2 [2,] 1 3 [3,] 2 4 [4,] 2 5 I wish to select the first observation for each id. That is, I want