只使最后一个课程间隔右侧闭合。

huangapple go评论96阅读模式
英文:

How can I make it so that only the last class interval is closed on the right?

问题

I'm trying to close only the last class interval of this exercise below, but I don't have much knowledge in r and the last interval is opening like all the others.

Code

  1. dados <- c(350, 356, 364, 369, 371, 375, 379, 384, 392,
  2. 350, 358, 364, 370, 371, 376, 380, 388,
  3. 351, 359, 365, 370, 372, 376, 380, 391,
  4. 352, 361, 365, 370, 372, 377, 381, 391,
  5. 352, 362, 366, 371, 373, 378, 382, 392,
  6. 354, 363, 368, 371, 374, 378, 383, 392)
  7. limites <- seq(min(dados), max(dados), by = 6)
  8. classes <- cut(dados, breaks = limites, right = FALSE)
  9. freqAbs <- table(classes)
  10. tabela <- data.frame(Classe = names(freqAbs),
  11. Frequencia = as.numeric(freqAbs))
  12. print(tabela)
  13. # Classe Frequencia
  14. # 1 [350,356) 6
  15. # 2 [356,362) 4
  16. # 3 [362,368) 7
  17. # 4 [368,374) 12
  18. # 5 [374,380) 8
  19. # 6 [380,386) 6
  20. # 7 [386,392) 3

(Note: I have provided the code as requested, but I did not translate the code itself.)

英文:

I'm trying to close only the last class interval of this exercise below, but I don't have much knowledge in r and the last interval is opening like all the others.

Code

  1. dados &lt;- c(350, 356, 364, 369, 371, 375, 379, 384, 392,
  2. 350, 358, 364, 370, 371, 376, 380, 388,
  3. 351, 359, 365, 370, 372, 376, 380, 391,
  4. 352, 361, 365, 370, 372, 377, 381, 391,
  5. 352, 362, 366, 371, 373, 378, 382, 392,
  6. 354, 363, 368, 371, 374, 378, 383, 392)
  7. limites &lt;- seq(min(dados), max(dados), by = 6)
  8. classes &lt;- cut(dados, breaks = limites, right = FALSE)
  9. freqAbs &lt;- table(classes)
  10. tabela &lt;- data.frame(Classe = names(freqAbs),
  11. Frequencia = as.numeric(freqAbs))
  12. print(tabela)
  13. # Classe Frequencia
  14. # 1 [350,356) 6
  15. # 2 [356,362) 4
  16. # 3 [362,368) 7
  17. # 4 [368,374) 12
  18. # 5 [374,380) 8
  19. # 6 [380,386) 6
  20. # 7 [386,392) 3

答案1

得分: 2

From ?cut, there is an argument include.lowest which

> include.lowest: 逻辑值,指示是否应包括等于最低值(或最高值,对于 right = FALSE)的 'breaks' 值。

You can use right = FALSE + include.lowest = TRUE to close the upper bound of the highest interval.

  1. classes &lt;- cut(dados, breaks = limites, right = FALSE, include.lowest = TRUE)
Output
  1. print(tabela)
  2. # Classe Frequencia
  3. # 1 [350,356) 6
  4. # 2 [356,362) 4
  5. # 3 [362,368) 7
  6. # 4 [368,374) 12
  7. # 5 [374,380) 8
  8. # 6 [380,386) 6
  9. # 7 [386,392] 6
英文:

From ?cut, there is an argument include.lowest which

> include.lowest: logical, indicating if an ‘x[i]’ equal to the lowest (or highest, for right = FALSE) ‘breaks’ value should be included.

You can use right = FALSE + include.lowest = TRUE to close the upper bound of the highest interval.

  1. classes &lt;- cut(dados, breaks = limites, right = FALSE, include.lowest = TRUE)
Output
  1. print(tabela)
  2. # Classe Frequencia
  3. # 1 [350,356) 6
  4. # 2 [356,362) 4
  5. # 3 [362,368) 7
  6. # 4 [368,374) 12
  7. # 5 [374,380) 8
  8. # 6 [380,386) 6
  9. # 7 [386,392] 6

huangapple
  • 本文由 发表于 2023年5月11日 10:20:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223723.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定