【发布时间】:2020-11-10 14:17:53
【问题描述】:
我有这两个数据框
> df1<-data.frame(day=c(monday,monday,monday,tuesday,tuesday,tuesday,wednesday,wednesday,wednesday),time=c(06:00,06:15,06:30,06:00,06:30,07:00,06:00,06:30,06:45),
> subject= c(ENG, GER, RUS, ENG, GER, RUS, ENG, GER, RUS))
>
>
> df2<-data.frame(time=c(06:00,06:15,06:30,06:45,07:00))
df1
day time subject
monday 06:00 ENG
monday 06:15 GER
monday 06:30 RUS
tuesday 06:00 ENG
tuesday 06:30 GER
tuesday 07:00 RUS
wednesday 06:00 ENG
wednesday 06:30 GER
wednesday 06:45 RUS
df2
time
06:00
06:15
06:30
06:45
07:00
我想得到这个
df3
day time subject
monday 06:00 ENG
monday 06:15 GER
monday 06:30 RUS
monday 06:45 NA
monday 07:00 NA
tuesday 06:00 ENG
tuesday 06:15 NA
tuesday 06:30 GER
tuesday 06:45 NA
tuesday 07:00 RUS
wednesday 06:00 ENG
wednesday 06:15 NA
wednesday 06:30 GER
wednesday 06:45 RUS
wednesday 07:00 NA
我试过了
merge(df1, df2, by = "time", all = TRUE, sort = FALSE)
但事实并非如此。
【问题讨论】: