I'm pretty sure, that a question like this was asked before but I cannot find any.
This is my dataset:
data.frame(Group = c("a", "b"),
MEAN_A = 1:2,
MEAN_B = 3:4,
MED_A = 5:6,
MED_B = 7:8)
Group MEAN_A MEAN_B MED_A MED_B
1 a 1 3 5 7
2 b 2 4 6 8
What I want is the following:
data.frame(Group = c("a", "a", "b", "b"),
Name = c("MEAN", "MED", "MEAN", "MED"),
Value_A = c(1, 5, 2, 6),
Value_B = c(3, 7, 4, 8))
Group Name Value_A Value_B
1 a MEAN 1 3
2 a MED 5 7
3 b MEAN 2 4
4 b MED 6 8
So I want to keep the variable Group
and have a new column which tells me, if the original variable was from MEAN
or MED
and two columns with the Values of A
and B
, that where initially in the variable names after MEAN
or MED
.
I've already tried pivot_longer
, even with patterns, but I'm not able to get my desired output.