For example you have this data frame :
dd <- data.frame(b = c("cpg1", "cpg2", "cpg3", "cpg4"),
x = c("A", "D", "A", "C"), y = c(8, 3, 9, 9),
z = c(1, 1, 1, 2))
dd
b x y z
1 cpg1 A 8 1
2 cpg2 D 3 1
3 cpg3 A 9 1
4 cpg4 C 9 2
I want to order the column names (b,x,y,z) by a row in another data frame which is:
d <- data.frame(pos = c("x", "z", "b"),
g = c("A", "D", "A"), h = c(8, 3, 9))
d
pos g h
1 x A 8
2 z D 3
3 b A 9
So I want to order the column name of dd with the row d$pos and dd also needs to have the same number in the row d$pos.
I tried with order and match but it did not give me the need result. My dataset is quite large, so something automtic would be ideal.
Thanks a lot for your help!