I am trying to merge two datasets using this function:
USA<-merge(USAdata,dow,by="Date",all=T)
When running it I run into the problem that the merge happens but the number of rows double, I've already successfully used this function to merge other data sets without any problems, and always by="Date".
Can someone help please?
Here are the datasets: https://drive.google.com/drive/folders/1KoG85vzZQ1R_C3mjXyRHyJJb4Cy6krKj?usp=sharing
PS I'm a total beginner
You have Date
class as character and in different format in dow
. Change it to date class and then merge
the data.
dow$Date <- as.Date(dow$Date, '%m/%d/%Y')
USA <- merge(USAdata, dow, by="Date", all=TRUE)
We can use tidyverse
library(dplyr)
library(lubridate)
USAdata %>%
full_join(dow %>% mutate(Date = mdy(Date)), by = 'Date')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.