Skip to content

Subset a datafram according to time

5 messages · MacQueen, Don, jim holtman, NickNz125

#
PREFERED WAY OF DOING IT 
I have a data set of observations every second for a month long period, I
want to extract the observations according to the  date & time of another
data frame ( the other data frame is in the same format). I want to do this
to match these  observations   to my test observations (in the other data
frame) which are done every 6 minutes. So basically im shrinking the data
frame of second observations to only display the date time observation every
6 minutes.

ALTERNATIVE WAY
In other words I just wanna extract every 6 minute observation value from
this dataframe of everysecond observations

date                time            observations
02/08/2011 00:00	 1.165	
02/08/2011 00:01	 1.241
02/08/2011 00:02	 1.232


Im pretty new to the porgram done 2 days on it learning and learning, im
getting my head around it.

Help would be much appreciated.

--
View this message in context: http://r.789695.n4.nabble.com/Subset-a-datafram-according-to-time-tp4372293p4372293.html
Sent from the R help mailing list archive at Nabble.com.
#
(apologies in advance for the stupid line-wrapping that I expect my email
software to force upon us)

If I understand correctly what you want, I would

(1) in both data frames, combine date and time into a single column
(variable) that is class POSIXct

(2) use the merge() function

This assumes that your every-6-minutes data frame does NOT have a column
with the same name as the observations in the every-second data frame. In
fact, it would be best if the only column name they have in common is the
date-time column.

Your question is a little puzzling because your example data is not one
obs per second, nor is it one per every 6 minutes.

This may help:
 as.POSIXct('01/12/2012 03:14:55', format='%m/%d/%Y %H:%M:%S')

or perhaps

 mydat$dt <- as.POSIXct( paste(mydat$date,mydat$time) , format='%m/%d/%Y
%H:%M:%S')

(supposing that your data frame is named mydat, and it has columns named
'date' and 'time' that look like those in your example.)

-Don
#
I want the combine and align by time DATAFRAME1 with DATAFRAME2.  DF1 is
second observations and DF2 6 minutes observations want to extract the ObsrG
data from DF1 to match the times in DF2. Therefore getting DF3 with
Observations (Obsrg) extracted from DF1 to match the times in DF2.

DATAFRAME1
Date  Time  ObsrG 
02/08/2011 00:00:01   1.167	 
02/08/2011 00:00:02   1.788	 
02/08/2011 00:00:03   1.677	 
02/08/2011 00:00:04   1.313	 
02/08/2011 00:00:05    1.110	 
02/08/2011 00:00:06    1.248		 
02/08/2011 00:00:07    1.187

DATAFRAME2
Date  Time  Obsr 
02/08/2011 00:00	 1.154	 
02/08/2011 00:06	 1.041	 
02/08/2011 00:12	 1.090	 
02/08/2011 00:18	 1.093	 
02/08/2011 00:24	 1.100	 
02/08/2011 00:30	 1.098		 
02/08/2011 00:36	 1.177	

DATAFRAME 3

Date  Time  Obsr ObsrG
02/08/2011 00:00	 1.154	2.456 
02/08/2011 00:06	 1.041	 2.341
02/08/2011 00:12	 1.090	 1.893
02/08/2011 00:18	 1.093	 1.783
02/08/2011 00:24	 1.100	 1.689
02/08/2011 00:30	 1.098	1.768	 
02/08/2011 00:36	 1.177	1.892


--
View this message in context: http://r.789695.n4.nabble.com/Subset-a-datafram-according-to-time-tp4372293p4375096.html
Sent from the R help mailing list archive at Nabble.com.
#
In the first line of dataframe 3, I don't see where the value of 2.456 for ObsrG came from.  Can you give us a hint of how that was computed?

Sent from my iPad
On Feb 9, 2012, at 21:05, NickNz125 <nickthomas125 at gmail.com> wrote:

            
3 days later