-6

For example, now I have:

A 1 1 1 1 3 4
B 1 8 9 7 9 6
A 2 3 4 5 6 6
C 1 1 1 1 1 1.

I want to get the rows with same letter A together, like this:

A 1 1 1 1 3 4
A 2 3 4 5 6 6

What should I do? It's in R programming.

the letters in front of every row is not the name of row, just the first element in each row

1 Answers1

0

You can use the order() function to do that:

# reading the data
df <- read.table(header=FALSE, text="A 1 1 1 1 3 4
B 1 8 9 7 9 6
A 2 3 4 5 6 6
C 1 1 1 1 1 1")

# ordering the data according to the values in the first colum
df[order(df[,1]),]
Jaap
  • 77,147
  • 31
  • 174
  • 185