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){ ...@@ -15,14 +15,20 @@ as_tbl_basic <- function(df,group){
names(res) <- switch(group, names(res) <- switch(group,
"none" = c("n","q0","q1","q2","q3","q4","IQR","m","sd","cv"), "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"), "YEAR" = c("YEAR","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"),
"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")) stop("group not recognized"))
if (group=="HOUR") {res$HOUR <- factor(res$HOUR, levels = res$HOUR)} if (group=="YEAR"){res$YEAR <- factor(res$YEAR, levels = res$YEAR)}
if (group=="WDAY") {res$WDAY <- factor(res$WDAY, levels = res$WDAY)}
if (group=="MONTH"){res$MONTH <- factor(res$MONTH, levels = res$MONTH)} 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)) class(res) <- c("tbl_basic",class(res))
return(res) return(res)
......
...@@ -2,26 +2,29 @@ ...@@ -2,26 +2,29 @@
#' basicr #' basicr
#' basicr #' basicr
#' @param dataset tbl_friendlyts object #' @param df tbl_friendlyts data.frame
#' @param target target #' @param target target
#' @param group group character #' @param group "none","YEAR","MONTH","WDAY","HOUR","MINUTE","SECOND"
#' @keywords basicr #' @keywords basicr
#' @export #' @export
#' @examples #' @examples
#' \dontrun{ #' \dontrun{
#' basicr() #' basicr()
#' } #' }
basicr <- function(dataset,target,group="none"){ basicr <- function(df,target,group="none"){
if (is.null(dataset) || (!inherits(dataset,"tbl_friendlyts")) ) { if (is.null(df) || (!inherits(df,"tbl_friendlyts")) ) {
stop("need non-null tbl_friendlyts dataset") stop("need non-null tbl_friendlyts df")
} }
res <- switch(group, res <- switch(group,
"none" = dataset %>% basic_(target=target), "none" = df %>% basic_(target=target),
"HOUR" = dataset %>% group_by(HOUR) %>% basic_(target=target), "YEAR" = df %>% group_by(YEAR) %>% basic_(target=target),
"WDAY" = dataset %>% group_by(wday) %>% basic_(target=target), "MONTH" = df %>% group_by(MONTH) %>% basic_(target=target),
"MONTH" = dataset %>% 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")) stop("group not recognized"))
class(res) <- class(res)[-which(class(res)=="tbl_friendlyts")] class(res) <- class(res)[-which(class(res)=="tbl_friendlyts")]
...@@ -33,7 +36,7 @@ basicr <- function(dataset,target,group="none"){ ...@@ -33,7 +36,7 @@ basicr <- function(dataset,target,group="none"){
#' basic_ #' basic_
#' basic_ #' basic_
#' @param dataset tbl_friendlyts object #' @param df tbl_friendlyts object
#' @param target character #' @param target character
#' @keywords basicr #' @keywords basicr
#' @export #' @export
...@@ -41,11 +44,11 @@ basicr <- function(dataset,target,group="none"){ ...@@ -41,11 +44,11 @@ basicr <- function(dataset,target,group="none"){
#' \dontrun{ #' \dontrun{
#' basic_() #' 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(), n = n(),
q0 = as.numeric(stats::quantile(targ,probs=0,na.rm=TRUE)), q0 = as.numeric(stats::quantile(targ,probs=0,na.rm=TRUE)),
q1 = as.numeric(stats::quantile(targ,probs=0.25,na.rm=TRUE)), q1 = as.numeric(stats::quantile(targ,probs=0.25,na.rm=TRUE)),
......
...@@ -22,4 +22,3 @@ as_tbl_basic() ...@@ -22,4 +22,3 @@ as_tbl_basic()
} }
} }
\keyword{basicr} \keyword{basicr}
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
\title{basic_ \title{basic_
basic_} basic_}
\usage{ \usage{
basic_(dataset, target) basic_(df, target)
} }
\arguments{ \arguments{
\item{dataset}{tbl_friendlyts object} \item{df}{tbl_friendlyts object}
\item{target}{character} \item{target}{character}
} }
...@@ -22,4 +22,3 @@ basic_() ...@@ -22,4 +22,3 @@ basic_()
} }
} }
\keyword{basicr} \keyword{basicr}
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
\title{basicr \title{basicr
basicr} basicr}
\usage{ \usage{
basicr(dataset, target, group = "none") basicr(df, target, group = "none")
} }
\arguments{ \arguments{
\item{dataset}{tbl_friendlyts object} \item{df}{tbl_friendlyts data.frame}
\item{target}{target} \item{target}{target}
\item{group}{group character} \item{group}{"none","YEAR","MONTH","WDAY","HOUR","MINUTE","SECOND"}
} }
\description{ \description{
basicr basicr
...@@ -24,4 +24,3 @@ basicr() ...@@ -24,4 +24,3 @@ basicr()
} }
} }
\keyword{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