0

How can I rearrange my data frame rows by a set order of index numbers?

for example:

$    PatNum Response
1       3       r
2       4       r
3      10       r
4      13       nr

This goes on for a total of 40 rows. I want to make row one starting with row 13, then 26, 1, 2, 61, 62, 63, etc. So it would look like:

$   PatNum Response
13      1       nr
26      2       nr
1       3       r
2       4       r
acylam
  • 18,231
  • 5
  • 36
  • 45
jclabrat
  • 35
  • 6

1 Answers1

3

Create example data

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))

Sort example data

data <- data[order(data$PatNum) , ]
Justin Meyer
  • 150
  • 1
  • 8