I've got an R data frame in the form of
my.data1 = data.frame(sex = c("m", "f"),
A = c(1, 2),
B = c(3, 4))
However, I'd like my data to be in the form of
my.data2 = data.frame(value = c(1, 2, 3, 4),
group = c("A", "A", "B", "B"),
sex = c("m", "f", "m", "f"))
So basically, I wanna turn some former columns ("A" and "B") into table cells under the new column "group" and simultaneously collect all former table cells under one new column "value".
What is the easiest way to convert the data accordingly?
Thanks in advance!