How does the cut function address null/missing values?

送分小仙女□ 提交于 2019-12-24 03:09:32

问题


I'm trying to use the cut() function in R to group continuous variables into buckets, like this:

as.character(cut(ORIG_AMT, breaks = c(-Inf, 0, 25000, 50000, 75000, 100000, 125000, 150000, 175000, 200000, 250000, 300000, 350000, 418000, Inf)
                                      , labels = c('Missing', '[0-25k)', '[25k-50k)', '[50k-75k)', '[75k-100k)', '[100k-125k)', '[125k-150k)','[150k-175k)', '[175k-200k)', '[200k-250k)', '[250k-300k)', '[300k-350k)', '[350k-418k)', '[418k+)'), right = FALSE, ordered = TRUE))

However, missing values are being omitted. I can't seem to find anywhere online that addresses this issue. Ideally, the missing values would all be grouped into the 'Missing' bucket.

Ultimately, I want to take weighed averages across these buckets. If there's a better way to approach this problem than with cut() and xtab() I'm open to it!

来源:https://stackoverflow.com/questions/31010248/how-does-the-cut-function-address-null-missing-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!