如何以新子集中的行将具有有序数字的方式对数据框进行子集化?

How can I subset a dataframe in a way that the rows in the new subset will have ordered numbers?

我有一个 df:

df = data.frame(a = c(1, 2, 3), b = c(3, 2, 1))

我像这样对 df 进行子集化:

df = df[2:3, ]

现在,当我检查 df 如下:

> df

  a b
2 2 2
3 3 1

第一个值的数字是 2,第二个值的数字是 3。我怎样才能对原始 df 进行子集化,使新的子集具有有序的数字?

期望的输出:

> df

  a b
1 2 2
2 3 1

将行名设置为 NULL

`row.names<-`(df[2:3, ], NULL)
  a b
1 2 2
2 3 1

或者默认更改 classtotibbleordata.tablewhich does not allow row.names i.e. it sets the row names toNULL`

> tibble::as_tibble(df[2:3, ])
# A tibble: 2 × 2
      a     b
  <dbl> <dbl>
1     2     2
2     3     1