[R] Selecting 3 different hours in a day

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Tue Nov 8 08:54:28 CET 2011


No data sample was provided, so with a verbal description of the problem comes a verbal answer.

I would use expand.grid to build a set of all desired date/time combinations, then use the merge function to select rows in your actual data.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

jck13 <jennakeane at hotmail.com> wrote:

>Hello,
>
>I have a csv with 5months of hourly data for 4 years. I would like to
>get
>9am, 12pm and 3pm from each day  and create a subset or a new data
>frame
>that I can analyze. The time are from hour 0-23 for each day.
>I am not sure how to create a loop which will take out each of these
>hours
>and create a subset.
>
>I was thinking of doing a for loop using the row number since:
>9am= row 10
>12pm= row 13
>3pm= row 16
>
>trying to loop through to extract these 3 times each day.
>
>n=length(date_stamp)
>             
>for (i in i:n) {
>m= 10
>i= 1
>new1= mv[m,]
>i= i+1
>m= m+3
>##m+18 at row 16?
>}
>
>I need some help creating a loop through this! Thank you! 
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Selecting-3-different-hours-in-a-day-tp4015010p4015010.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list