Commit 83ad5993 authored by jml's avatar jml
Browse files

add group year, minute, second

parent 7febf751
......@@ -15,14 +15,20 @@ as_tbl_basic <- function(df,group){
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"),
"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"),
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=="YEAR"){res$YEAR <- factor(res$YEAR, levels = res$YEAR)}
if (group=="MONTH"){res$MONTH <- factor(res$MONTH, levels = res$MONTH)}
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)}
class(res) <- c("tbl_basic",class(res))
return(res)
......
......@@ -2,26 +2,29 @@
#' basicr
#' basicr
#' @param dataset tbl_friendlyts object
#' @param df tbl_friendlyts data.frame
#' @param target target
#' @param group group character
#' @param group "none","YEAR","MONTH","WDAY","HOUR","MINUTE","SECOND"
#' @keywords basicr
#' @export
#' @examples
#' \dontrun{
#' basicr()
#' }
basicr <- function(dataset,target,group="none"){
basicr <- function(df,target,group="none"){
if (is.null(dataset) || (!inherits(dataset,"tbl_friendlyts")) ) {
stop("need non-null tbl_friendlyts dataset")
if (is.null(df) || (!inherits(df,"tbl_friendlyts")) ) {
stop("need non-null tbl_friendlyts df")
}
res <- switch(group,
"none" = dataset %>% basic_(target=target),
"HOUR" = dataset %>% group_by(HOUR) %>% basic_(target=target),
"WDAY" = dataset %>% group_by(wday) %>% basic_(target=target),
"MONTH" = dataset %>% group_by(MONTH) %>% basic_(target=target),
"none" = df %>% basic_(target=target),
"YEAR" = df %>% group_by(YEAR) %>% basic_(target=target),
"MONTH" = df %>% group_by(MONTH) %>% basic_(target=target),
"WDAY" = df %>% group_by(wday) %>% basic_(target=target),
"HOUR" = df %>% group_by(HOUR) %>% basic_(target=target),
"MINUTE" = df %>% group_by(MINUTE) %>% basic_(target=target),
"SECOND" = df %>% group_by(SECOND) %>% basic_(target=target),
stop("group not recognized"))
class(res) <- class(res)[-which(class(res)=="tbl_friendlyts")]
......@@ -33,7 +36,7 @@ basicr <- function(dataset,target,group="none"){
#' basic_
#' basic_
#' @param dataset tbl_friendlyts object
#' @param df tbl_friendlyts object
#' @param target character
#' @keywords basicr
#' @export
......@@ -41,11 +44,11 @@ basicr <- function(dataset,target,group="none"){
#' \dontrun{
#' basic_()
#' }
basic_ <- function(dataset,target){
basic_ <- function(df,target){
names(dataset)[names(dataset)==target] <- "targ"
names(df)[names(df)==target] <- "targ"
res <- dataset %>% summarise(
res <- df %>% summarise(
n = n(),
q0 = as.numeric(stats::quantile(targ,probs=0,na.rm=TRUE)),
q1 = as.numeric(stats::quantile(targ,probs=0.25,na.rm=TRUE)),
......
......@@ -22,4 +22,3 @@ as_tbl_basic()
}
}
\keyword{basicr}
......@@ -5,10 +5,10 @@
\title{basic_
basic_}
\usage{
basic_(dataset, target)
basic_(df, target)
}
\arguments{
\item{dataset}{tbl_friendlyts object}
\item{df}{tbl_friendlyts object}
\item{target}{character}
}
......@@ -22,4 +22,3 @@ basic_()
}
}
\keyword{basicr}
......@@ -5,14 +5,14 @@
\title{basicr
basicr}
\usage{
basicr(dataset, target, group = "none")
basicr(df, target, group = "none")
}
\arguments{
\item{dataset}{tbl_friendlyts object}
\item{df}{tbl_friendlyts data.frame}
\item{target}{target}
\item{group}{group character}
\item{group}{"none","YEAR","MONTH","WDAY","HOUR","MINUTE","SECOND"}
}
\description{
basicr
......@@ -24,4 +24,3 @@ basicr()
}
}
\keyword{basicr}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment