如何从级别中减去数字
我想将一个值范围为 0-70 的向量剪切为 x 个类别,并且想要每个类别的上限。到目前为止,我已经使用 cut()
尝试过此操作,并尝试从级别中提取限制。 我有一个级别列表,我想从中提取每个级别的第二个数字。如何提取 space 和 ] 之间的值(这是我感兴趣的数字)?
我有:
> levels(bins)
[1] "(-0.07,6.94]" "(6.94,14]" "(14,21]" "(21,28]" "(28,35]"
[6] "(35,42]" "(42,49]" "(49,56]" "(56,63.1]" "(63.1,70.1]"
并且想得到:
[1] 6.94 14 21 28 35 42 49 56 63.1 70.1
或者有更好的方法来计算类别的上限吗?
I would like to cut a vector of values ranging 0-70 to x number of categories, and would like the upper limit of each category. So far, I have tried this using cut()
and am trying to extract the limits from levels.
I have a list of levels, from which I would like to extract the second number from each level. How can I extract the values between space and ] (which is the number I'm interested in)?
I have:
> levels(bins)
[1] "(-0.07,6.94]" "(6.94,14]" "(14,21]" "(21,28]" "(28,35]"
[6] "(35,42]" "(42,49]" "(49,56]" "(56,63.1]" "(63.1,70.1]"
and would like to get:
[1] 6.94 14 21 28 35 42 49 56 63.1 70.1
Or is there a better way of calculating the upper bounds of categories?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是一种解决
方案
This could be one solution
gives
如果您想要精确的中断值,那么您应该自己计算它们,导致间隔的
cut
轮限制:您可以查看代码以
cut.default
如何breaks< /code> 是计算:
简单的方法就是获取此代码并将其放入函数中:
结果是
If you want exact values of breaks then you should compute them yourself, cause
cut
round limits for interval:You could look on code to
cut.default
howbreaks
are compute:So easy way is to grab this code and put into a function:
Result is