I have a matrix already set and I am trying to sort it in order of sample id and its associated number.
I have sample id's in mixed order from V1-V26 and I want the matrix to be in the order of V1-V26 and not mixed. How can I sort the matrix in R by the first column of sample id's in ascending order?
Update with second code
r<-read.table("testbray.csv", header = TRUE, sep = ",", check.names = FALSE)
i1 <- as.numeric(sub("\\D+", "", row.names(r)))
j1 <- as.numeric(sub("\\D+", "", colnames(r)))
y<-r[order(i1), order(j1)]
>
dput(head(r[, c(1, 3)]))
structure(list(structure(c(16L, 12L, 3L, 17L, 5L, 22L), .Label = c("V1",
"V10", "V11", "V12", "V13", "V14", "V15", "V17", "V18", "V19",
"V2", "V20", "V21", "V22", "V23", "V24", "V25", "V26", "V27",
"V3", "V4", "V5", "V6", "V7", "V8", "V9"), class = "factor"),
V20 = c(0.592334495, 0, 0.893728223, 0.625048393, 0.587882307,
0.647502904)), row.names = c(NA, 6L), class = "data.frame")