'Expand a data frame by group

I have a big data frame which consists of 1000 data frames (500x500), and I created by following code:

setwd("user/all_csv")
archivos <- list.files(full.names = F)
big.df <- lapply(archivos, read.csv, header = TRUE) %>%
       set_names(archivos)%>%
       bind_rows(.id = 'grp')

The big.df looks like below (a small example):

grp           X    X1     X2     X5
2020_01_19    1    23     47     3
2020_01_19    2    13     45     54
2020_01_19    5    23     41     21
2020_01_20    1    65     32     19
2020_01_20    2    39     52     12
2020_01_20    5    43     76     90
...

How can I generate the output below?:

             1-X1   1-X2   1-X5    2-X1    2-X2    2-X5    5-X1    5-X2    5-X5
2020_01_19    23     47     3       13      45      54      23      41      21
2020_01_20    65     32     19      39      52      12      43      76      90
...

I don't really know how to proceed. Any help would be greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source