enter image description hereI want the intervals to be of the form [161,168) and [182,189], instead of as they appear in the attached image, that is to say, that the intervals have parentheses and brackets. enter image description here

library(grid)
library(gridExtra) 

LI <- sample(155:165, 1) 
a <-sample(5:10, 1) 
lim <-seq ( from =LI ,by=a , length =5)
limites <- function (m ){
v <-NULL
for (i in 1: m){
v <-c(v , paste ( lim [i] ," -" , lim [i +1]) )
}
v
}
intervalos <- limites (4)
frecuencias <- sample (10:30 ,4)
tabla <-data.frame (intervalos , frecuencias)
colnames ( tabla ) <-c("Intervalos" ,"Frecuencias ")
marcasdeclase <- function (v){
vect <-NULL
n <- length (v) -1
for (k in 1: n) vect <-c( vect , mean (c(v[ k],v[k +1]) ) )
vect
}



<<echo=FALSE, results=hide, fig=TRUE,width=7.5,height=4>>=

tabla <-data.frame (intervalos , frecuencias )
colnames (tabla) <-c("Intervalos" ,"Frecuencias ")

grid.table(tabla, rows = NULL)

@

推荐答案

您将在limites函数中将这些值构建为字符串.更改该函数以包括适当的圆括号/方括号.

limites <- function (m ){
  v <-NULL
  for (i in 1: m){
    v <-c(v , paste ("[", lim [i] ," -" , lim [i +1], ifelse(i==m,"]",")")))
  }
  v
}

enter image description here

R相关问答推荐

删除facet_wrap标签之间的水平线

R等效于LABpascal(n,1)不同的列符号

x[[1]]中的错误:脚注越界

如何修复R码的置换部分?

在R中为马赛克图中的每个字段着色

R根据条件进行累积更改

如何根据嵌套元素的名称高效而优雅地确定它属于哪个列表?

多个过滤器内的一个盒子在仪表板Quarto

在ggplot2中更改小提琴情节的顺序

以相同的方式对每个表进行排序

R中边际效应包中Logistic回归的交互作用风险比

将全局环境变量的名称分配给列表中的所有元素

变长向量的矢量化和

我需要使用ggplot2制作堆叠条形图

对R中的列表列执行ROW Mean操作

名字的模糊匹配

生存时间序列的逻辑检验

R-如何在ggplot2中显示具有不同x轴值(日期)的多行?

如何修改GT表中组名行的 colored颜色 ?

将某个阈值以下的列中的值分类到不同的列中,否则保持该列的原样