eliavs
eliavs

Reputation: 2356

similar to excel vlookup

Hi
i have a 10 year, 5 minutes resolution data set of dust concentration
and i have seperetly a 15 year data set with a day resolution of the synoptic clasification how can i combine these two datasets they are not the same length or resolution
here is a sample of the data

> head(synoptic)
        date synoptic
1 01/01/1995        8    
2 02/01/1995        7    
3 03/01/1995        7    
4 04/01/1995       20    
5 05/01/1995        1   
6 06/01/1995        1       
>    
head(beit.shemesh)
  X........................ StWd  SHT PRE  GSR RH Temp  WD  WS PM10  CO   O3    
1                        NA   64 19.8   0 -2.9 37 15.2  61 2.2  241 0.9 40.6    
2                        NA   37 20.1   0  1.1 38 15.2 344 2.1  241 0.9 40.3    
3                        NA   36 20.2   0  0.7 39 15.1  32 1.9  241 0.9 39.4    
4                        NA   52 20.1   0  0.9 40 14.9  20 2.1  241 0.9 38.7    
5                        NA   42 19.0   0  0.9 40 14.6  11 2.0  241 0.9 38.7    
6                        NA   75 19.9   0  0.2 40 14.5 341 1.3  241 0.9 39.1    
  No2 Nox  No SO2                       date    
1 1.4 2.9 1.5 1.6  31/12/2000 24:00             
2 1.7 3.1 1.4 0.9  01/01/2001 00:05             
3 2.1 3.5 1.4 1.2  01/01/2001 00:10             
4 2.7 4.2 1.5 1.3  01/01/2001 00:15             
5 2.3 3.8 1.5 1.4  01/01/2001 00:20             
6 2.8 4.3 1.5 1.3  01/01/2001 00:25 

any idea's

Upvotes: 3

Views: 3318

Answers (1)

Joris Meys
Joris Meys

Reputation: 108583

Make an extra column for calculating the dates, and then merge. To do this, you have to generate a variable in each dataframe bearing the same name, hence you first need some renaming. Also make sure that the merge column you use has the same type in both dataframes :

beit.shemesh$datetime <- beit.shemesh$date
beit.shemesh$date <- as.Date(beith.shemesh$datetime,format="%d/%m/%Y")
synoptic$date <- as.Date(synoptic$date,format="%d/%m/%Y")
merge(synoptic, beit.shemesh,by="date",all.y=TRUE)

Using all.y=TRUE keeps the beit.shemesh dataset intact. If you also want empty rows for all non-matching rows in synoptic, you could use all=TRUE instead.

Upvotes: 7

Related Questions