我想在裁掉较大的标记后保留订单。可重现的示例:
else .
结果:
require(dplyr)
data <- c(rnorm(25, 2000, 500), 19, 10)
data <- data %>% cut(., breaks = 5, dig.lab = 4)
levels(data)
当我更改格式时:
"(7.265,557]" "(557,1104]" "(1104,1651]" "(1651,2198]" "(2198,2748]"
订单更改。因为我有不同的数据集,如何在不进行手动更改的情况下保留数据?
答案 0 :(得分:0)
使用factor
并从levels
显式指定data
library(dplyr)
nd_data <- data %>%
prettyNum(big.mark = ".") %>%
factor(., levels = prettyNum(levels(data), big.mark = "."))
levels(data)
#[1] "(6.802,649.6]" "(649.6,1289]" "(1289,1929]" "(1929,2568]" "(2568,3211]"
levels(nd_data)
#[1] "(6.802,649.6]" " (649.6,1289]" "(1.289,1.929]" "(1.929,2.568]" "(2.568,3.211]"
数据
set.seed(1234)
data <- c(rnorm(25, 2000, 500), 19, 10)
data <- data %>% cut(., breaks = 5, dig.lab = 4)