Hello to all, I have two dataframes, the first with two columns sunrise and sunset (for 10 years). Each of these columns is formatted for date time (ex: 01-Jan-2010 15:37:00) In the second data frame I have GPS information and also a date time column (same format ). What I would like to do is a subset of all the rows from the second dataframe that occurred in day time only so between sunrise and sunset. There are thousands of lines from multiple GPS so date time might be repeated in some rows. Any ideas how to accomplish this? Thanks in advance Patrao -- View this message in context: http://r.789695.n4.nabble.com/Loop-to-find-dates-whithin-dates-tp3264180p3264180.html Sent from the R help mailing list archive at Nabble.com.
?subset Daniel Nordlund Bothell, WA USA> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] > On Behalf Of patraopedro > Sent: Monday, February 07, 2011 6:11 AM > To: r-help at r-project.org > Subject: [R] Loop to find dates whithin dates > > > Hello to all, > > I have two dataframes, the first with two columns sunrise and sunset (for > 10 > years). Each of these columns is formatted for date time (ex: 01-Jan-2010 > 15:37:00) > > In the second data frame I have GPS information and also a date time > column > (same format ). > > What I would like to do is a subset of all the rows from the second > dataframe that occurred in day time only so between sunrise and sunset. > There are thousands of lines from multiple GPS so date time might be > repeated in some rows. > > Any ideas how to accomplish this? > > Thanks in advance > > Patrao > > -- > View this message in context: http://r.789695.n4.nabble.com/Loop-to-find- > dates-whithin-dates-tp3264180p3264180.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.
Hi Patrao, you can 'merge' both datasets using the (extracted) day as indicator, see ?merge. Then use subset. hth. Am 07.02.2011 15:10, schrieb patraopedro:> > Hello to all, > > I have two dataframes, the first with two columns sunrise and sunset (for 10 > years). Each of these columns is formatted for date time (ex: 01-Jan-2010 > 15:37:00) > > In the second data frame I have GPS information and also a date time column > (same format ). > > What I would like to do is a subset of all the rows from the second > dataframe that occurred in day time only so between sunrise and sunset. > There are thousands of lines from multiple GPS so date time might be > repeated in some rows. > > Any ideas how to accomplish this? > > Thanks in advance > > Patrao >-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790
If you are looking to find out if a given GPS time is between sunrise/sunset, then here is what I would do given the quantity of data. I would encode the sunrise/sunset times in a character vector of length 10 years * 365 days/year * 1440 minutes/day = 5M character vector. Set the vector to '1' if between the times. Now all you have to do is convert you GPS times to an index into this vector and if it is '1' then you know that you are between sunrist/sunset. Saves having to compare each GPS time to the 3650 entries in you database. On Mon, Feb 7, 2011 at 9:10 AM, patraopedro <patraopedro at yahoo.com.br> wrote:> > Hello to all, > > I have two dataframes, the first with two columns sunrise and sunset (for 10 > years). Each of these columns is formatted for date time (ex: 01-Jan-2010 > 15:37:00) > > In the second data frame I have GPS information and also a date time column > (same format ). > > What I would like to do is a subset of all the rows from the second > dataframe that occurred in day time only so between sunrise and sunset. > There are thousands of lines from multiple GPS so date time might be > repeated in some rows. > > Any ideas how to accomplish this? > > Thanks in advance > > Patrao > > -- > View this message in context: http://r.789695.n4.nabble.com/Loop-to-find-dates-whithin-dates-tp3264180p3264180.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. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?