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

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

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

dados <- c(350, 356, 364, 369, 371, 375, 379, 384, 392,
           350, 358, 364, 370, 371, 376, 380, 388,
           351, 359, 365, 370, 372, 376, 380, 391,
           352, 361, 365, 370, 372, 377, 381, 391,
           352, 362, 366, 371, 373, 378, 382, 392,
           354, 363, 368, 371, 374, 378, 383, 392)

limites <- seq(min(dados), max(dados), by = 6)
classes <- cut(dados, breaks = limites, right = FALSE)
freqAbs <- table(classes)
tabela <- data.frame(Classe = names(freqAbs),
                     Frequencia = as.numeric(freqAbs))

print(tabela)

#      Classe Frequencia
# 1 [350,356)          6
# 2 [356,362)          4
# 3 [362,368)          7
# 4 [368,374)         12
# 5 [374,380)          8
# 6 [380,386)          6
# 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

dados &lt;- c(350, 356, 364, 369, 371, 375, 379, 384, 392,
           350, 358, 364, 370, 371, 376, 380, 388,
           351, 359, 365, 370, 372, 376, 380, 391,
           352, 361, 365, 370, 372, 377, 381, 391,
           352, 362, 366, 371, 373, 378, 382, 392,
           354, 363, 368, 371, 374, 378, 383, 392)

limites &lt;- seq(min(dados), max(dados), by = 6)
classes &lt;- cut(dados, breaks = limites, right = FALSE)
freqAbs &lt;- table(classes)
tabela &lt;- data.frame(Classe = names(freqAbs),
                     Frequencia = as.numeric(freqAbs))

print(tabela)

#      Classe Frequencia
# 1 [350,356)          6
# 2 [356,362)          4
# 3 [362,368)          7
# 4 [368,374)         12
# 5 [374,380)          8
# 6 [380,386)          6
# 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.

classes &lt;- cut(dados, breaks = limites, right = FALSE, include.lowest = TRUE)
Output
print(tabela)

#      Classe Frequencia
# 1 [350,356)          6
# 2 [356,362)          4
# 3 [362,368)          7
# 4 [368,374)         12
# 5 [374,380)          8
# 6 [380,386)          6
# 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.

classes &lt;- cut(dados, breaks = limites, right = FALSE, include.lowest = TRUE)
Output
print(tabela)

#      Classe Frequencia
# 1 [350,356)          6
# 2 [356,362)          4
# 3 [362,368)          7
# 4 [368,374)         12
# 5 [374,380)          8
# 6 [380,386)          6
# 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:

确定