Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

r - How to reset row names?

Here is a sample data set:

sample1 <- data.frame(Names=letters[1:10], Values=sample(seq(0.1,1,0.1)))

When I'm reordering the data set, I'm losing the row names order

sample1[order(sample1$Values), ]
    Names Values
 7      g    0.1
 4      d    0.2
 3      c    0.3
 9      i    0.4
10      j    0.5
 5      e    0.6
 8      h    0.7
 6      f    0.8
 1      a    0.9
 2      b    1.0

Desired output:

    Names Values
 1      g    0.1
 2      d    0.2
 3      c    0.3
 4      i    0.4
 5      j    0.5
 6      e    0.6
 7      h    0.7
 8      f    0.8
 9      a    0.9
10      b    1.0
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try

rownames(Ordersample2) <- 1:10

or more generally

rownames(Ordersample2) <- NULL

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...