I am looking to melt a table, but some of the variables are similarly named and I'm having trouble using the patterns function.
Here is an example of what my data looks like:
Date | ID | X_a | X_ab | X_c | X_d | Y_a | Y_ab | Y_c | Y_d |
---|---|---|---|---|---|---|---|---|---|
3/18/2022 10:57:17 PM | 001 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 2 |
This is how I would like it to look like:
Date | ID | Group | a | ab | c | d |
---|---|---|---|---|---|---|
3/18/2022 10:57:17 PM | 001 | X | 1 | 0 | 0 | 1 |
3/18/2022 10:57:17 PM | 001 | Y | 1 | 0 | 1 | 2 |
When I use melt, first it has an issue because date is a different type than the remaining variables (character vs. integers) and secondly when I tried without date, the patterns uses "a" and finds additionally ab. Any ideas on how to get this done, either by modifying this method or using a totally different one? It's important to note that this should be something which can be run on large amounts of data.