Hello. I have a list of (consistently) poorly formatted data frames. I've spent much of the morning trying to figure out a solution using purrr and it's proving very frustrating. Here's some example data:
my_list <- list(
data.frame(Jack = c("Anne", "Sophie"), X. = "$", X1 = 2:3, X..1 = "$", X4 = 5:6),
data.frame(Meg = c("Tom", "Lauren", "Kyle", "Alex", "Seth"), X. = "$", X7 = 8:12, X..1 = "$", X13 = 14:18),
data.frame(Dylan = "Liz", X. = "$", X19 = 20, X..1 = "$", X21 = 22)
)
my_list
#> [[1]]
#> Jack X. X1 X..1 X4
#> 1 Anne $ 2 $ 5
#> 2 Sophie $ 3 $ 6
#>
#> [[2]]
#> Meg X. X7 X..1 X13
#> 1 Tom $ 8 $ 14
#> 2 Lauren $ 9 $ 15
#> 3 Kyle $ 10 $ 16
#> 4 Alex $ 11 $ 17
#> 5 Seth $ 12 $ 18
#>
#> [[3]]
#> Dylan X. X19 X..1 X21
#> 1 Liz $ 20 $ 22
Note that each data frame has the same number of columns.
Problems:
- The first row of data is stored as the column names.
- There are separate columns for dollar signs ($).
What I hope to accomplish:
- Move the column names down into a row.
- Rename each column (a simple
x1:x(n) scheme is fine).
- Dropping the columns containing "$" is not a problem, as I can just do it later on. Buuuuut if anyone thinks that it would be better before I combine the data frames, please say so
PS - If you provide any rlang or tidy evaluation context in your response, I would really appreciate it. I'm trying to get a better grasp of it.