as_tbl_basic.R 1.31 KB
Newer Older
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
1
2
3
4
5
6

#' as_tbl_basic

#' as_tbl_basic
#' @param df data.frame
#' @param group group character
Jean-Marie Lepioufle's avatar
typo    
Jean-Marie Lepioufle committed
7
#' @keywords basicr
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
8
9
10
11
12
13
14
15
16
17
#' @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"),
jml's avatar
jml committed
18
19
20
21
22
23
    "YEAR"    = c("YEAR","n","q0","q1","q2","q3","q4","IQR","m","sd","cv"),
    "MONTH"   = c("MONTH","n","q0","q1","q2","q3","q4","IQR","m","sd","cv"),
    "WDAY"    = c("WDAY" ,"n","q0","q1","q2","q3","q4","IQR","m","sd","cv"),
    "HOUR"    = c("HOUR" ,"n","q0","q1","q2","q3","q4","IQR","m","sd","cv"),
    "MINUTE"  = c("MINUTE" ,"n","q0","q1","q2","q3","q4","IQR","m","sd","cv"),
    "SECOND"  = c("SECOND" ,"n","q0","q1","q2","q3","q4","IQR","m","sd","cv"),
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
24
25
    stop("group not recognized"))

jml's avatar
jml committed
26
  if (group=="YEAR"){res$YEAR <- factor(res$YEAR, levels = res$YEAR)}
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
27
  if (group=="MONTH"){res$MONTH <- factor(res$MONTH, levels = res$MONTH)}
jml's avatar
jml committed
28
29
30
31
  if (group=="WDAY") {res$WDAY <- factor(res$WDAY, levels = res$WDAY)}
  if (group=="HOUR") {res$HOUR <- factor(res$HOUR, levels = res$HOUR)}
  if (group=="MINUTE") {res$MINUTE <- factor(res$MINUTE, levels = res$MINUTE)}
  if (group=="SECOND") {res$SECOND <- factor(res$SECOND, levels = res$SECOND)}
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
32
33
34
35

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