prp
prp

Reputation: 33

Join two dataframes with same column name on the basis of Time Stamp

I have two dataframes with hourly data.

First Data frame is named DENVER as shown below.

Timestamp Heating_energy Lighting_Energy Total_Energy
01/01/2021 00:00 2 6 8
01/01/2021 01:00 5 5 10
01/01/2021 02:00 5 1 6

Second Data frame is named CHICAGO as shown below.

Timestamp Heating_energy Lighting_Energy Total_Energy
01/01/2021 00:00 1 1 2
01/01/2021 01:00 6 1 7
01/01/2021 02:00 2 6 8

Two data frames have same timestamp. But I want to join them column wise..

Timestamp Heating_energy_DENVER Lighting_Energy_DENVER Total_Energy_DENVER Heating_energy_CHICAGO Lighting_Energy_CHICAGO Total_Energy_CHICAGO
01/01/2021 00:00 2 6 8 1 1 2
01/01/2021 01:00 5 5 10 6 1 7
01/01/2021 02:00 5 1 6 2 6 8

How can I make this work in R? Thank you so much for looking at this question.

Upvotes: 0

Views: 26

Answers (1)

PaulS
PaulS

Reputation: 25323

Try this:

merge(DENVER,CHICAGO,by="Timestamp",suffixes=c("_DENVER","_CHICAGO"))

Upvotes: 1

Related Questions