Re: [R] Splitting times into groups based on a range of times

2013-10-13 Thread arun
Hi Ben, It looks like the condition is not met in majority of the split elements.  So, when you create a dataframe with the a column with 0 element and another column with an element, it shows the Error message. data.frame(dt2=NULL,group=1) #Error in data.frame(dt2 = NULL, group = 1) :  # argum

Re: [R] Splitting times into groups based on a range of times

2013-10-11 Thread arun
---o School of Geography, University of Leeds, Leeds, LS2 9JT o---------------o Tel: +44(0)113 34 33345 Mob: +44(0)770 868 7641 o---o http://www.geog.leeds.ac.uk/ o

Re: [R] Splitting times into groups based on a range of times

2013-10-11 Thread Benjamin Gillespie
-------------o Tel: +44(0)113 34 33345 Mob: +44(0)770 868 7641 o---o http://www.geog.leeds.ac.uk/ o-o @RiversBenG o--o From: arun [smartpink...@yahoo

Re: [R] Splitting times into groups based on a range of times

2013-10-11 Thread arun
Also, df1 <- do.call(rbind,lapply(split(df,df$group),function(x) data.frame(dt2=seq(x[1,1],x[nrow(x),1],by="15 min"),group=x[1,2]))) id1<- df1[,2][match(as.POSIXct(dt),df1[,1])]  id1[is.na(id1)]<- 0  identical(id1,id) #[1] TRUE A.K, On Thursday, October 10, 2013 9:29 PM, arun wrote: Hi Ben, I

Re: [R] Splitting times into groups based on a range of times

2013-10-10 Thread arun
Hi Ben, I would look into ?findInterval() or ?cut() for an easier solution. indx<- match(df[,1],as.POSIXct(dt))  indx2<- unique(df[,2]) lst1<- lapply(split(indx,((seq_along(indx)-1)%/%2)+1),function(x) seq(x[1], x[2]))  res <- unlist(lapply(seq_along(lst1),function(i) {                           

[R] Splitting times into groups based on a range of times

2013-10-10 Thread Benjamin Gillespie
Hi all, I hope you can help with this one! I have a dataframe: 'df' that consists of a vector of times: 'dt2' and a vector of group id's: 'group': dates2=rep("01/02/13",times=8) times2=c("12:00:00","12:30:00","12:45:00","13:15:00","13:30:00","14:00:00","14:45:00","17:30:00") y =paste(dates2, ti