0

I have 2 data frame, one has time stamp and temperature and the other has time stamps. I wanna copy the temperature data from first data set to second one if the time stamp is identical !

I have checked this and this likns. But they are different to my question.

Can someone help me on this ? Here is a sample of my data :

data1
               date    t
1  19.11.2016 06:20 22.1
2  19.11.2016 06:30 22.4
3  19.11.2016 06:40 22.6
4  19.11.2016 06:50 22.8
5  19.11.2016 07:00 23.2
6  19.11.2016 07:10 23.3
7  19.11.2016 07:20 23.7
8  19.11.2016 07:30 23.9
9  19.11.2016 07:40 24.0
10 19.11.2016 07:50 24.4
11 19.11.2016 08:00 24.5
12 19.11.2016 08:10 24.7
13 19.11.2016 08:20 25.0
14 19.11.2016 08:30 25.3
15 19.11.2016 08:40 25.4
16 19.11.2016 08:50 25.7
17 19.11.2016 09:00 25.8
18 19.11.2016 09:10 25.9
19 19.11.2016 09:20 25.9
20 19.11.2016 09:30 26.1
21 19.11.2016 09:40 26.3
22 19.11.2016 09:50 26.4
23 19.11.2016 10:00 26.6
24 19.11.2016 10:10 26.5
25 19.11.2016 10:20 26.5
26 19.11.2016 10:30   NA
27 19.11.2016 10:40   NA
28 21.11.2016 06:30   NA
29 21.11.2016 06:40   NA
30 21.11.2016 06:50   NA
31 21.11.2016 07:00   NA
32 21.11.2016 07:10   NA
33 21.11.2016 07:20 20.9
34 21.11.2016 07:30 21.0
35 21.11.2016 07:40 21.0
36 21.11.2016 07:50 21.1
37 21.11.2016 08:00 21.2
38 21.11.2016 08:10 21.3
39 21.11.2016 08:20 21.5
40 21.11.2016 08:30 21.8
41 21.11.2016 08:40 22.1
42 21.11.2016 08:50 22.2
43 21.11.2016 09:00 22.6
44 21.11.2016 09:10 22.9
45 21.11.2016 09:20 22.7
46 21.11.2016 09:30 22.6
47 21.11.2016 09:40 22.6
48 21.11.2016 09:50 22.7
49 21.11.2016 10:00 22.8
50 21.11.2016 10:10 23.1
51 21.11.2016 10:20 23.6

data2
               date
1  19.11.2016 06:20
2  19.11.2016 06:30
3  19.11.2016 06:40
4  19.11.2016 06:50
5  19.11.2016 07:00
6  19.11.2016 07:10
7  19.11.2016 07:20
8  19.11.2016 07:30
9  19.11.2016 07:40
10 19.11.2016 07:50
11 19.11.2016 08:00
12 19.11.2016 08:10
13 19.11.2016 08:20
14 19.11.2016 08:30
15 19.11.2016 08:40
16 19.11.2016 08:50
17 19.11.2016 09:00
18 19.11.2016 09:10
19 19.11.2016 09:20
20 19.11.2016 09:30
21 19.11.2016 09:40
22 19.11.2016 09:50
23 19.11.2016 10:00
24 19.11.2016 10:10
25 19.11.2016 10:20
26 21.11.2016 07:20
27 21.11.2016 07:30
28 21.11.2016 07:40
29 21.11.2016 07:50
30 21.11.2016 08:00
31 21.11.2016 08:10
32 21.11.2016 08:20
33 21.11.2016 08:30
34 21.11.2016 08:40
35 21.11.2016 08:50
36 21.11.2016 09:00
37 21.11.2016 09:10
38 21.11.2016 09:20
39 21.11.2016 09:30
40 21.11.2016 09:40
41 21.11.2016 09:50
42 21.11.2016 10:00
43 21.11.2016 10:10
44 21.11.2016 10:20
45 21.11.2016 10:30
46 21.11.2016 10:40
47 21.11.2016 10:50
48 21.11.2016 11:00
49 21.11.2016 11:10
50 21.11.2016 11:20
51 21.11.2016 11:30
Ali Hadjihoseini
  • 941
  • 1
  • 11
  • 31

2 Answers2

1

Given that the question is tagged dplyr,

library(dplyr)
right_join(data1, data2, by="date")

This will join your data sets together. I suggested a right-join which will include all rows from data2 even if there is no match in data1 - https://rpubs.com/NateByers/Merging

EDIT: Updated column names in join

anotherfred
  • 1,330
  • 19
  • 25
1

Simple solution using base R merge:

merge(data2, data1, all.x = TRUE)
pogibas
  • 27,303
  • 19
  • 84
  • 117