英文:
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 <- 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
答案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 <- 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 <- 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论