Re: [R] merge by time, certain value if 5 min before and after an event

2014-10-04 Thread Dagmar
Thank you Jean, Petr, Terry, William and everyone else who thought about my problem. It is sooo good that this mailing list exists! I solved my problem using Petr's suggestion, that didn't seem so complicated and worked fine for me. Thanks again and have a great weekend, Dagmar Am 02.10.2014

Re: [R] merge by time, certain value if 5 min before and after an event

2014-10-03 Thread PIKAL Petr
Hi If Jean's guess is correct, after simple changing Timestamp to real date see ?strptime and ?as.POSIXct you can use result - merge(mydata, myframe, all=TRUE) use function ?na.locf from zoo package to fill NAs in Event column and get rid of all rows with NA in location e.g. by

Re: [R] merge by time, certain value if 5 min before and after an event

2014-10-03 Thread PIKAL Petr
Hi So if I understand correctly, you want to spread value high to times 5 minutes before its occurrence and 5 minutes after its occurrence. If your dates are not extremely big you can prepare its expanded version and use code suggestions I sent previously myframe - data.frame

[R] merge by time, certain value if 5 min before and after an event

2014-10-03 Thread Therneau, Terry M., Ph.D.
I've attached two functions used locally. (The attachments will be stripped off of the r-help response, but the questioner should get them). The functions neardate and tmerge were written to deal with a query that comes up very often in our medical statistics work, some variety of get the

Re: [R] merge by time, certain value if 5 min before and after an event

2014-10-03 Thread William Dunlap
Hi Terry, Some of that combination of sort() and approx() can be done by findInterval(), which may be quick enough that you don't need the 'thinning' part of the code. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Oct 3, 2014 at 6:05 AM, Therneau, Terry M., Ph.D. thern...@mayo.edu

[R] merge by time, certain value if 5 min before and after an event

2014-10-02 Thread Dagmar
Hello! I hope someone can help me. It would save me days of work. Thanks in advance! I have two dataframes which look like these: myframe - data.frame (Timestamp=c(24.09.2012 09:00:00, 24.09.2012 10:00:00, 24.09.2012 11:00:00), Event=c(low,high,low) ) myframe mydata - data.frame (

Re: [R] merge by time, certain value if 5 min before and after an event

2014-10-02 Thread Adams, Jean
Dagmar, Can you explain more fully why rows 1, 2, and 5 in your result are low and rows 3 and 4 are high? It is not clear to me from the information you have provided. result[c(1, 2, 5), ] Timestamp location Event 1 24.09.2012 09:05:011 low 2 24.09.2012 09:49:502

Re: [R] merge by time, certain value if 5 min before and after an event

2014-10-02 Thread Dagmar
Dear Jean and all, I want all lines to be low, but during times 9:55 - 10:05 a.m (i.e. a timespan of 10 min) I want them to be high. In my real data low and high refer to lowtide and hightide in the waddensea and I want to assign the location of my animal at the time it was taken to the tide

Re: [R] merge by time, certain value if 5 min before and after an event

2014-10-02 Thread Adams, Jean
Thanks, Dagmar. So, shouldn't row 3 with a time of 09:51:01 be low and not high? Jean On Thu, Oct 2, 2014 at 4:25 PM, Dagmar ramga...@gmx.net wrote: Dear Jean and all, I want all lines to be low, but during times 9:55 - 10:05 a.m (i.e. a timespan of 10 min) I want them to be high. In my