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

Solution 1:

Try

rownames(Ordersample2) <- 1:10

or more generally

rownames(Ordersample2) <- NULL

Solution 2:

I had a dplyr usecase:

df %>% as.data.frame(row.names = 1:nrow(.))