ntile 函数在最新版本的 R 中不起作用
ntile function not working in latest version of R
我的数据是
my_basket <- data.frame(ITEM_GROUP = c("Fruit","Fruit","Fruit","Fruit","Fruit","Vegetable","Vegetable","Vegetable","Vegetable","Dairy","Dairy","Dairy","Dairy","Dairy"),
ITEM_NAME = c("Apple","Banana","Orange","Mango","Papaya","Carrot","Potato","Brinjal","Raddish","Milk","Curd","Cheese","Milk","Paneer"),
Price = c(100,80,80,90,65,70,60,70,25,60,40,35,50,120))
我想使用 ntile 函数计算百分位数列
df1 = mutate(my_basket, percentile_rank = ntile(my_basket$Price,100))
它应该给我一个看起来像 correct_df
的数据框
correct_df<- data.frame(ITEM_GROUP = c("Fruit","Fruit","Fruit","Fruit","Fruit","Vegetable","Vegetable","Vegetable","Vegetable","Dairy","Dairy","Dairy","Dairy","Dairy"),
ITEM_NAME = c("Apple","Banana","Orange","Mango","Papaya","Carrot","Potato","Brinjal","Raddish","Milk","Curd","Cheese","Milk","Paneer"),
Price = c(100,80,80,90,65,70,60,70,25,60,40,35,50,120),
percentile_rank=c(86,65,72,79,43,51,29,58,1,36,15,8,22,93))
但是我得到的数据框看起来像 wrong_df
wrong_df<- data.frame(ITEM_GROUP = c("Fruit","Fruit","Fruit","Fruit","Fruit","Vegetable","Vegetable","Vegetable","Vegetable","Dairy","Dairy","Dairy","Dairy","Dairy"),
ITEM_NAME = c("Apple","Banana","Orange","Mango","Papaya","Carrot","Potato","Brinjal","Raddish","Milk","Curd","Cheese","Milk","Paneer"),
Price = c(100,80,80,90,65,70,60,70,25,60,40,35,50,120),
percentile_rank=c(13,10,11,12,7,8,5,9,1,6,3,3,4,14))
自从我将 R 版本更新到 4.0.2 后才出现此问题
我认为这不是 R 问题,但似乎是 dplyr
1.0.0 的问题,如 this open GitHub issue 中所述。查看从那里获取的两个函数的输出差异。
ntile_083(my_basket$Price,100)
#[1] 86 65 72 79 43 51 29 58 1 36 15 8 22 93
ntile_100(my_basket$Price,100)
#[1] 13 10 11 12 7 8 5 9 1 6 3 2 4 14
您现在可以使用 ntile_083
获得以前的功能。
我的数据是
my_basket <- data.frame(ITEM_GROUP = c("Fruit","Fruit","Fruit","Fruit","Fruit","Vegetable","Vegetable","Vegetable","Vegetable","Dairy","Dairy","Dairy","Dairy","Dairy"),
ITEM_NAME = c("Apple","Banana","Orange","Mango","Papaya","Carrot","Potato","Brinjal","Raddish","Milk","Curd","Cheese","Milk","Paneer"),
Price = c(100,80,80,90,65,70,60,70,25,60,40,35,50,120))
我想使用 ntile 函数计算百分位数列
df1 = mutate(my_basket, percentile_rank = ntile(my_basket$Price,100))
它应该给我一个看起来像 correct_df
的数据框correct_df<- data.frame(ITEM_GROUP = c("Fruit","Fruit","Fruit","Fruit","Fruit","Vegetable","Vegetable","Vegetable","Vegetable","Dairy","Dairy","Dairy","Dairy","Dairy"),
ITEM_NAME = c("Apple","Banana","Orange","Mango","Papaya","Carrot","Potato","Brinjal","Raddish","Milk","Curd","Cheese","Milk","Paneer"),
Price = c(100,80,80,90,65,70,60,70,25,60,40,35,50,120),
percentile_rank=c(86,65,72,79,43,51,29,58,1,36,15,8,22,93))
但是我得到的数据框看起来像 wrong_df
wrong_df<- data.frame(ITEM_GROUP = c("Fruit","Fruit","Fruit","Fruit","Fruit","Vegetable","Vegetable","Vegetable","Vegetable","Dairy","Dairy","Dairy","Dairy","Dairy"),
ITEM_NAME = c("Apple","Banana","Orange","Mango","Papaya","Carrot","Potato","Brinjal","Raddish","Milk","Curd","Cheese","Milk","Paneer"),
Price = c(100,80,80,90,65,70,60,70,25,60,40,35,50,120),
percentile_rank=c(13,10,11,12,7,8,5,9,1,6,3,3,4,14))
自从我将 R 版本更新到 4.0.2 后才出现此问题
我认为这不是 R 问题,但似乎是 dplyr
1.0.0 的问题,如 this open GitHub issue 中所述。查看从那里获取的两个函数的输出差异。
ntile_083(my_basket$Price,100)
#[1] 86 65 72 79 43 51 29 58 1 36 15 8 22 93
ntile_100(my_basket$Price,100)
#[1] 13 10 11 12 7 8 5 9 1 6 3 2 4 14
您现在可以使用 ntile_083
获得以前的功能。