Re: [R] Data-frame selection

2015-10-11 Thread Jeff Newmiller
Sorry, looked like there were a different number of rows in the results because the rownames were different. I also see that the OP was interested in any Groups, not just the two in the example, so your solution probably meets the requirements better than mine -

Re: [R] Data-frame selection

2015-10-11 Thread Cacique Samurai
Hi Peter and Jeff! Thanks very much for your code! Both worked perfectly in my data set!! All best, Raoni 2015-10-10 21:40 GMT-03:00 peter dalgaard : > >> On 11 Oct 2015, at 02:12 , Jeff Newmiller wrote: >> >> Sorry I missed the boat the first time, and while it looks like Peter is >> getting

Re: [R] Data-frame selection

2015-10-10 Thread peter dalgaard
> On 11 Oct 2015, at 02:12 , Jeff Newmiller wrote: > > Sorry I missed the boat the first time, and while it looks like Peter is > getting closer I suspect that is not quite there either due to the T2 being > considered separate from T3 requirement. Er, what do you mean by that? As far as I

Re: [R] Data-frame selection

2015-10-10 Thread Jeff Newmiller
Sorry I missed the boat the first time, and while it looks like Peter is getting closer I suspect that is not quite there either due to the T2 being considered separate from T3 requirement. Here is another stab at it: library(dplyr) # first approach is broken apart to show the progression of t

Re: [R] Data-frame selection

2015-10-10 Thread peter dalgaard
These situations where the desired results depend on the order of observations in a dataset do tend to get a little tricky (this is one kind of problem that is easier to handle in a SAS DATA step with its sequential processing paradigm). I think this will do it: keep <- function(d) with(d, {

Re: [R] Data-frame selection

2015-10-10 Thread Cacique Samurai
Hello Jeff! Thanks very much for your prompt reply, but this is not exactly what I need. I need the first sequence of records. In example that I send, I need the first seven lines of group "T2" in ID "1" (lines 3 to 9) and others six lines of group "T3" in ID "1" (lines 10 to 15). I have to discar

Re: [R] Data-frame selection

2015-10-10 Thread Jeff Newmiller
?aggregate in base R. Make a short function that returns the first element of a vector and give that to aggregate. Or... library(dplyr) ( test %>% group_by( ID, Group ) %>% summarise( Var=first( Var ) ) %>% as.data.frame ) ---

[R] Data-frame selection

2015-10-10 Thread Cacique Samurai
Hello R-Helpers! I have a data-frame as below (dput in the end of mail) and need to select just the first sequence of occurrence of each "Group" in each "ID". For example, for ID "1" I have two sequential occurrences of T2 and two sequential occurrences of T3: > test [test$ID == 1, ] ID Group