dimanche 20 mars 2016

R: How to merge two data frame based on different date

I want to merge two dataset based on date and define specific date as different category. The first data.frame is the water quality data with the date.Shown as follows (first a few columns of the data).

Organization   ID Latitude Longitude       Date Year Month Day       Depth
1        NJHDG   19  40.6475 -74.17350 2010-06-02 2010     6   2     Surface
2        NJHDG   14  40.7919 -74.07837 2010-06-03 2010     6   3 Near Bottom
3        NJHDG    2  40.9212 -74.17550 2010-06-07 2010     6   7    Midwater
4        NJHDG    5  40.8795 -74.12066 2010-06-09 2010     6   9    Midwater
5 31ISC2RS_WQX HR8A  40.9850 -73.90833 2010-06-10 2010     6  10     Surface
6        NJHDG    6  40.8890 -74.08166 2010-06-14 2010     6  14    Midwater

Now, I have another data.frame that is a precipitation data(sample shown as follows).

    Date   PrecipitationIn
    128 2010-05-08            0.03
    129 2010-05-09            0.00
    130 2010-05-10            0.00
    131 2010-05-11            0.04
    132 2010-05-12            0.33
    133 2010-05-13            0.00

The question is that I want to define the date in the first data frame as "wet day" if the current date, previous one day, previous two day has >=0.2 inches by using the precipitation data. For example,for the date "2010-06-02" in the first data frame. If either "2010-5-31" or "2010-6-01" or"2010-6-02"has >=0.2 inches precipitation,I will define "2010-06-02" as "wet day". else, I will define "dry day". I tried to used for loop and if function to define, but I failed. Anyone has smart ideas to help me solve this problem? I really appreciate it.

Aucun commentaire:

Enregistrer un commentaire