醉H 2022-11-04 02:30 采纳率: 100%
浏览 58
已结题

R语言tb1.contineous.normal函数是哪个R包的?

各位,苦找这函数的R包却不得
希望得到各位解惑~
tb1.contineous.normal
tb1.categorial
tb1.contineous.not.normal

源代码如下:

chtable <-  function (design, cv = NULL, cv.nn = NULL, gv = NULL, by = NULL, 
                     c_meanSQse = FALSE, c_meanPMse = FALSE, c_ci = FALSE, g_N = FALSE, 
                     g_percent = FALSE, g_perSQse = FALSE, g_NSQper = FALSE, g_nSQper = FALSE, 
                     g_ci = FALSE, g_direction = "v", total = FALSE, round = 2, 
                     view = T, xlsx = NULL) 
{
  ck.by <- list(cv = cv, gv = gv, cv.nn = cv.nn, by = by)
  (ck.by <- ck.by[!sapply(ck.by, is.null)])
  if (length(ck.by) > 1) {
    for (i in 1:(length(ck.by) - 1)) {
      for (j in (i + 1):length(ck.by)) {
        if (names(ck.by)[i] == "cv" & names(ck.by)[j] == 
            "cv.nn") 
          (next)(j)
        ck.common <- set::and(ck.by[[i]], ck.by[[j]])
        if (length(ck.common) > 0) 
          stop(names(ck.by)[i], " and ", names(ck.by)[j], 
               " have the same variable: ", paste0(ck.common, 
                                                   collapse = ", "))
      }
    }
  }
  v <- c(cv, cv.nn, gv)
  lv <- set::not(v, colnames(design$variables))
  if (length(lv) > 0) {
    if (do::cnOS()) 
      stop(tmcn::toUTF8("变量 "), paste0(lv, collapse = ", "), 
           tmcn::toUTF8(" 输入错误"))
    if (!do::cnOS()) 
      stop("variable ", paste0(lv, collapse = ", "), " not exist")
  }
  r1 <- NULL
  if (!is.null(cv)) {
    r1 <- tb1.contineous.normal(design, cv, by, meanSQse = c_meanSQse, 
                                meanPMse = c_meanPMse, ci = c_ci, total, round)
  }
  r2 <- NULL
  if (!is.null(cv.nn)) {
    r2 <- tbl.contineous.not.normal(design, cv.nn, by, total, 
                                    round)
  }
  r3 <- NULL
  if (!is.null(gv)) {
    r3 <- tb1.categorial(design, x = gv, by, value = g_N, 
                         per = g_percent, perSQse = g_perSQse, NSQper = g_NSQper, 
                         nSQper = g_nSQper, ci = g_ci, direction = g_direction, 
                         total = total, round)
  }
  r <- plyr::rbind.fill(r1, r2)
  r <- plyr::rbind.fill(r, r3)
  row.names(r) <- NULL
  if (view) 
    nhs_view.svytableone(r)
  r$variable <- do::Replace(r$variable, "~~~~", "    ")
  if (!is.null(xlsx)) {
    header_bold <- openxlsx::createStyle(textDecoration = "Bold")
    wb <- openxlsx::createWorkbook()
    openxlsx::addWorksheet(wb, "Sheet1")
    for (i in 1:ncol(r)) {
      openxlsx::writeData(wb, sheet = 1, x = colnames(r)[i], 
                          startCol = i, startRow = 1, headerStyle = header_bold)
      if (i == 1) {
        for (j in 1:nrow(r)) {
          if (do::left(r[j, i], 4) == "    ") {
            openxlsx::writeData(wb, sheet = 1, x = r[j, 
                                                     i], startCol = i, startRow = j + 1)
          }
          else {
            openxlsx::writeData(wb, sheet = 1, x = r[j, 
                                                     i], startCol = i, startRow = j + 1, headerStyle = header_bold)
          }
        }
      }
      else if (grepl("p", colnames(r)[i], T)) {
        for (j in 1:nrow(r)) {
          if (nchar(r[j, i]) > 0) {
            ii <- tryCatch(as.numeric(r[j, i]), warning = function(w) "w")
            if ((ii == "w" | ii <= 0.05) & r[j, i] != 
                "ref") {
              openxlsx::writeData(wb, sheet = 1, x = ii, 
                                  startCol = i, startRow = j + 1, headerStyle = header_bold)
            }
          }
          else {
            openxlsx::writeData(wb, sheet = 1, x = r[j, 
                                                     i], startCol = i, startRow = j + 1)
          }
        }
      }
      else {
        openxlsx::writeData(wb, sheet = 1, x = r[, i], 
                            startCol = i, startRow = 2)
      }
    }
    openxlsx::saveWorkbook(wb, xlsx, overwrite = TRUE)
  }
  invisible(r)
}

  • 写回答

3条回答 默认 最新

  • 「已注销」 2022-11-04 07:49
    关注

    把代码发给我看看

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月4日
  • 已采纳回答 11月4日
  • 修改了问题 11月4日
  • 创建了问题 11月4日

悬赏问题

  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信
  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到
  • ¥50 高维数据处理方法求指导
  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错