在R中创建间隔

发布于 2025-02-13 06:26:19 字数 408 浏览 0 评论 0原文

我想在R中创建间隔,我已经有一些代码来获得特定的数字。

例如,以下内容:

"33" "45" "77" "82" "85"

作为我想获得以下内容的结果,最重要的是要获得范围,它不必像这样:

c(0,33), c(34,45), c(46,77), c(78,82), c(83,85), c(86,100)

如何在任何给定的数字示例中实现这一目标? 0应该始终是最小值,而100始终是最大值。

我已经尝试过这样的事情,但是显然这是不起作用的,因为k没有定义:

for(number in numbers) {
    interval = c(number[k] +1, number[k+1])

I want to create intervals in R, I already got some code to get specific numbers.

For example the following:

"33" "45" "77" "82" "85"

As the result I want to get the following, the most important is to get the ranges, it doesnt have to look like this exactly:

c(0,33), c(34,45), c(46,77), c(78,82), c(83,85), c(86,100)

How can I achieve this for any given example of numbers? 0 should always be the minimum and 100 always the max.

I have tried something like this, but obviously this can't work because k is not defined:

for(number in numbers) {
    interval = c(number[k] +1, number[k+1])

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

真心难拥有 2025-02-20 06:26:19

在矩阵中

x=c(33,45,77,82,85)
cbind(
  c(0,x+1),
  c(x,100)
)

     [,1] [,2]
[1,]    0   33
[2,]   34   45
[3,]   46   77
[4,]   78   82
[5,]   83   85
[6,]   86  100

In a matrix

x=c(33,45,77,82,85)
cbind(
  c(0,x+1),
  c(x,100)
)

     [,1] [,2]
[1,]    0   33
[2,]   34   45
[3,]   46   77
[4,]   78   82
[5,]   83   85
[6,]   86  100
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文