as_tbl_basic.R 872 Bytes
Newer Older
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#' as_tbl_basic

#' as_tbl_basic
#' @param df data.frame
#' @param group group character
#' @keywords diagnr
#' @export
#' @examples
#' \dontrun{
#' as_tbl_basic()
#' }
as_tbl_basic <- function(df,group){
  res <- tibble::as_tibble(df)

  names(res) <- switch(group,
    "none"    = c("n","q0","q1","q2","q3","q4","IQR","m","sd","cv"),
    "HOUR"  = c("HOUR" ,"n","q0","q1","q2","q3","q4","IQR","m","sd","cv"),
    "WDAY"  = c("WDAY" ,"n","q0","q1","q2","q3","q4","IQR","m","sd","cv"),
    "MONTH" = c("MONTH","n","q0","q1","q2","q3","q4","IQR","m","sd","cv"),
    stop("group not recognized"))

  if (group=="HOUR") {res$HOUR <- factor(res$HOUR, levels = res$HOUR)}
  if (group=="WDAY") {res$WDAY <- factor(res$WDAY, levels = res$WDAY)}
  if (group=="MONTH"){res$MONTH <- factor(res$MONTH, levels = res$MONTH)}

  class(res) <- c("tbl_basic",class(res))
  return(res)
}