r - How to create a new table from two tables by using lag dates? -


i struggling few things 1) want make new table (df3) 2 tables 1 df1 has lot of data points 12,000 rows has got column names below. aqs_site_id location of sites data collected there multiple sites each unique site id. want match site id with, sites in df2 matrix. made sites in df2 mapping zipcodes coordinates (site_latitude , site_longitude). should create new table df3 taking previous day or previous 1 week concentration of pm25 (df2 date 2011/02/14 previous 1 day or 1 week in df1, need match aqs_site_id , site location).

[1] "str_date"
[2] "aqs_site_id"
[3] "poc"
[4] "dailymeanpm25concentration" [5] "units"
[6] "daily_aqi_value"
[7] "daily_obs_count"
[8] "percent_complete"
[9] "aqs_parameter_code"
[10] "aqs_parameter_desc"
[11] "csa_code"
[12] "csa_name"
[13] "cbsa_code"
[14] "cbsa_name"
[15] "state_code"
[16] "state"
[17] "county_code"
[18] "county"
[19] "site_latitude"
df2

 date         emmi      act      pm25   site_id     2011/02/12   12345     21       11     xyz     2011/02/14   14321     22       12     yer     2011/02/19   12345     21       13     xyz     2011/02/23   43211     13       12     yer     2011/02/23   56341     13       12     yer 

finally should have table df3

date emmi act pm25 site_id lag1daypm25 lag2daypm25 lag1weekpm25 sum1weekpm25

i take @ duplicated version:

to answer qauestion, have use merge command:

result = merge( df1, df2, all=true) 

this should answer question


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -