如何按索引编号的设定顺序重新排列数据框行?
例如:
$ PatNum Response
1 3 r
2 4 r
3 10 r
4 13 nr
这总共持续了40行。我想从第13行开始第一行,然后是26,1,2,61,62,63等。所以它看起来像:
$ PatNum Response
13 1 nr
26 2 nr
1 3 r
2 4 r
答案 0 :(得分:1)
one <- c(3, 4, 10, 1, 2, 5)
two <- c("nr", "nr", "r", "r", "nr", "nr")
data <- cbind(one, two)
data <- as.data.frame(data)
names(data) <- c("PatNum", "Response")
data$PatNum <- as.numeric(as.character(data$PatNum))
data <- data[order(data$PatNum) , ]