I have searched through web but I could not find a solution to my problem. I have a data like below
df <- structure(list(V1 = c("ATP1A2", "CAPRIN1", "ATP1A1", "CBX3",
"AUP1", "LARS2", "MTHFD1", "VDAC2", "PRKCSH", "ATP1B1", "B3GNT3",
"", ""), V2 = c("ATP1A1", "ATP1A2", "ATP1B1", "AUP1", "B3GNT3",
"CAPRIN1", "CAPRIN1", "CBX3", "", "", "", "", ""), V3 = c("220948_s_at",
"203296_s_at", "201243_s_at", "220525_s_at", "204856_at", "200722_s_at",
"200723_s_at", "200037_s_at", "", "", "", "", ""), V4 = c("LARS2",
"MTHFD1", "PRKCSH", "PRKCSH", "VDAC2", "", "", "", "", "", "",
"", ""), V5 = c("204016_at", "202309_at", "200707_at", "214080_x_at",
"211662_s_at", "", "", "", "", "", "", "", "")), .Names = c("V1",
"V2", "V3", "V4", "V5"), row.names = c(NA, -13L), class = "data.frame")
what I am trying to do is to sort the column 2 and 4 based on first column. however if I sort the second column, the third column will change according to the V2 and fifth column according to the V4.
Expected output is like below
V1 V2 V3 V4 V5
1 ATP1A2 ATP1A2 203296_s_at - -
2 CAPRIN1 CAPRIN1 200722_s_at - -
3 - CAPRIN1 200723_s_at - -
4 ATP1A1 ATP1A1 220948_s_at - -
5 CBX3 CBX3 200037_s_at - -
6 AUP1 AUP1 220525_s_at - -
7 LARS2 - - LARS2 204016_at
8 MTHFD1 - - MTHFD1 202309_at
9 VDAC2 - - VDAC2 211662_s_at
10 PRKCSH - - PRKCSH 200707_at
11 - - - PRKCSH 214080_x_at
12 ATP1B1 ATP1B1 201243_s_at - -
13 B3GNT3 B3GNT3 204856_at - -
I want to sort the V2 and V4 based on V1. Note that V3 corresponds to V2 and V5 corresponds to V4. for example if V2 changes V3 changes and so on.
I did try the following which did not help me
df2<- df[with(df, order(V1)), ]
I tried the following too but did not work
require(data.table)
df2 <- data.table(df, key="V1")
The following as well did not work
df2<- df[order(df$V1),]