I have two sets of data:
Unique ID |
---|
1 |
2 |
3 |
Date |
---|
2020 |
2021 |
2022 |
Is there a way to merge this so the data looks like below?
Unique ID | Date |
---|---|
1 | 2020 |
1 | 2021 |
1 | 2022 |
2 | 2020 |
2 | 2021 |
2 | 2022 |
3 | 2020 |
3 | 2021 |
3 | 2022 |
Appreciate any help. Thanks!
CodePudding user response:
Maybe this work for you
> df1 <- data.frame(UniqueID = 1:3)
> df2 <- data.frame(Date = 2020:2022)
> expand.grid(c(df1, df2))
UniqueID Date
1 1 2020
2 2 2020
3 3 2020
4 1 2021
5 2 2021
6 3 2021
7 1 2022
8 2 2022
9 3 2022