醉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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探