醉H 2022-11-03 18:30 采纳率: 100%
浏览 60
已结题

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-03 23:49
    关注

    把代码发给我看看

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

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月4日
  • 已采纳回答 11月4日
  • 修改了问题 11月4日
  • 创建了问题 11月3日
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部