R语言中,对数据框中的水果数量进行排序
时间: 2023-06-26 22:04:11 浏览: 116
假设数据框名为`df`,其中有一个列名为`fruit`,另一个列名为`quantity`,你可以使用`order()`函数对`quantity`列进行排序,并返回排序后的`fruit`列。代码如下:
```R
df$fruit[order(df$quantity)]
```
如果你想按照降序排列,可以在`order()`函数中添加`decreasing = TRUE`参数。代码如下:
```R
df$fruit[order(df$quantity, decreasing = TRUE)]
```
相关问题
R语言中,对数据框中的列名为水果数量的列数据进行排序进行排序
假设你的数据框名为`df`,其中有一列名为`水果数量`,你可以使用`order()`函数对该列进行排序,如下所示:
```R
df <- df[order(df$水果数量),]
```
这将根据`水果数量`列中的值对整个数据框进行升序排序。如果要进行降序排序,可以在`order()`函数中添加`decreasing = TRUE`参数,如下所示:
```R
df <- df[order(df$水果数量, decreasing = TRUE),]
```
阅读全文
相关推荐














