Skip to content

Commit

Permalink
version 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
aiien61 authored and cran-robot committed Jul 7, 2016
1 parent 9ed7111 commit e2cfe51
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 28 deletions.
12 changes: 7 additions & 5 deletions DESCRIPTION
@@ -1,18 +1,20 @@
Package: tigerhitteR
Type: Package
Title: Pre-Process of Time Series Data Set in R
Version: 1.0.1
Date: 2016-07-05
Version: 1.0.2
Date: 2016-07-08
Author: Will Kuan <aiien61will@gmail.com>
Maintainer: Will Kuan <aiien61will@gmail.com>
Description: Pre-process for discrete time series data set which is not continuous at the column
of 'date'. Refilling records of missing 'date' and other columns to the hollow data set so that
final data set is able to be dealt with time series analysis.
License: GPL (>= 3)
URL: https://github.com/Willdata/tigerhitteR
LazyData: TRUE
RoxygenNote: 5.0.1
Depends: zoo (>= 1.7-12), openxlsx (>= 3.0.0)
Imports: openxlsx (>= 3.0.0), zoo (>= 1.7-13), Hmisc (>= 3.17-4)
Depends: R (>= 3.3.1)
NeedsCompilation: no
Packaged: 2016-07-05 07:24:35 UTC; will.kuan
Packaged: 2016-07-07 18:11:13 UTC; will.kuan
Repository: CRAN
Date/Publication: 2016-07-05 11:01:45
Date/Publication: 2016-07-07 23:52:13
6 changes: 3 additions & 3 deletions MD5
@@ -1,6 +1,6 @@
a821679ae390b677a049ee3f5137e185 *DESCRIPTION
d4b5aaf4fc002307f0b4bc894b837682 *NAMESPACE
234829e3243e4c3bc034f6f62af9aca8 *R/tigerhitteR.R
c02a8a36f7530901852f772894317f16 *DESCRIPTION
d84cc096f71b9e92752dc605d6b9f4d5 *NAMESPACE
627fa4d7c996179bff929a586bfff62a *R/tigerhitteR.R
9122cb0ccfb11fb24ff32f2b015572ee *data/data.example.rda
32fa7739cad4285c6b4aad9a242ec2ea *man/data.example.Rd
5f523a5b5685c3a5f13ad71268f6c62c *man/dateRefill.fromData.Rd
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Expand Up @@ -2,6 +2,8 @@

export(dateRefill.fromData)
export(dateRefill.fromsFile)
import(Hmisc)
import(openxlsx)
import(zoo)
importFrom(utils,head)
importFrom(utils,install.packages)
66 changes: 46 additions & 20 deletions R/tigerhitteR.R
Expand Up @@ -8,8 +8,8 @@
#' @param fixedVec A row of column number which should be kept same values with the original
#' @param pChanged The column number which should be changed to different value into new record.
#' @param pChangedNum The value of a specific column which should be put into the new record.
#' @import zoo openxlsx
#' @importFrom utils head
#' @import openxlsx zoo Hmisc
#' @importFrom utils head install.packages
#' @details Real time series sales dataset could be not continuous in 'date' field. e.g., monthly sales data is continuous,
#' but discrete in daily data.
#'
Expand All @@ -22,17 +22,26 @@ dateRefill.fromsFile <-
function(inPath, sheet, dateCol, outPath, fixedVec, pChanged, pChangedNum)
{
if(!requireNamespace("openxlsx",quietly = TRUE)){
stop("Please install package 'openxlsx'")
install.packages("openxlsx"); requireNamespace("openxlsx", quietly = TRUE)
#stop("Please install package 'openxlsx'. ")
}else{
requireNamespace("openxlsx", quietly = TRUE)
}

if(!requireNamespace("zoo", quietly = TRUE)){
stop("Please install package 'zoo'")
install.packages("zoo"); requireNamespace("zoo", quietly = TRUE)
#stop("Please install package 'zoo'. ")
}else{
requireNamespace("zoo", quietly = TRUE)
}

if(!requireNamespace("Hmisc",quietly = TRUE)){
install.packages("Hmisc"); requireNamespace("Hmisc", quietly = TRUE)
#stop("Please install package 'Hmisc'. ")
}else{
requireNamespace("Hmisc", quietly = TRUE)
}

data <- openxlsx::read.xlsx(inPath, sheet)

data[,dateCol] <- zoo::as.Date(data[,dateCol], origin = "1899-12-30")
Expand All @@ -42,8 +51,7 @@ dateRefill.fromsFile <-

data$Date <- as.POSIXlt(data$Date) # transform to POSIXlt type

y.min <- min(data$Date$year + 1900)
y.max <- max(data$Date$year + 1900)
year.list <- levels(factor(data$Date$year + 1900))

### sorting data
inc.order <- order(data$Date, decreasing = FALSE)
Expand All @@ -60,18 +68,23 @@ dateRefill.fromsFile <-
diff <- zoo::as.Date(data[1,2])-origin
rm(year)

days <- as.numeric((y.max-y.min+1)*365-diff)
daySum <- 0
for(x in year.list)
{
daySum <- daySum + Hmisc::yearDays(zoo::as.Date(paste(x, "-01-01", sep = "")))
}
daySum <- as.numeric(daySum - diff)

final.data[1:days,] <- NA # remove first few null days because data is not start on 1/1
final.data[,2] <- seq(data[1,2], by = "1 days", length.out = days)
final.data[1:daySum,] <- NA # remove first few null days because data is not start on 1/1
final.data[,2] <- seq(data[1,2], by = "1 days", length.out = daySum)

#### setting rownames
rownames(data) <- c(1:nrow(data))

my.index <- match(data$Date, as.POSIXlt(final.data$Date))
final.data[my.index,] <- data[,]

for(i in days:1)
for(i in daySum:1)
{
if(!is.na(final.data[i,1])){
tag <- i
Expand All @@ -91,7 +104,7 @@ dateRefill.fromsFile <-
}
}

final.data$Date <- as.Date(final.data$Date) # for correcting date time in excel
final.data$Date <- zoo::as.Date(final.data$Date) # for correcting date time in excel

colnames(final.data) <- colNameVector

Expand All @@ -108,7 +121,8 @@ dateRefill.fromsFile <-
#' @param fixedVec A row of column number which should be kept same values with the original
#' @param pChanged The column number which should be changed to different value into new record.
#' @param pChangedNum The value of a specific column which should be put into the new record.
#' @import zoo openxlsx
#' @import zoo Hmisc
#' @importFrom utils head install.packages
#' @return The dataset which is completed.
#' @details Real time series sales dataset could be not continuous in 'date' field. e.g., monthly sales data is continuous,
#' but discrete in daily data.
Expand All @@ -124,11 +138,19 @@ dateRefill.fromData <-
function(data, dateCol, fixedVec, pChanged, pChangedNum)
{
if(!requireNamespace("zoo", quietly = TRUE)){
stop("Please install package 'zoo'")
install.packages("zoo"); requireNamespace("zoo", quietly = TRUE)
#stop("Please install package 'zoo'. ")
}else{
requireNamespace("zoo", quietly = TRUE)
}

if(!requireNamespace("Hmisc",quietly = TRUE)){
install.packages("Hmisc"); requireNamespace("Hmisc", quietly = TRUE)
#stop("Please install package 'Hmisc'. ")
}else{
requireNamespace("Hmisc", quietly = TRUE)
}

data <- data.frame(data)

data[,dateCol] <- zoo::as.Date(data[,dateCol], origin = "1899-12-30")
Expand All @@ -138,8 +160,7 @@ dateRefill.fromData <-

data$Date <- as.POSIXlt(data$Date) # transform to POSIXlt type

y.min <- min(data$Date$year + 1900)
y.max <- max(data$Date$year + 1900)
year.list <- levels(factor(data$Date$year + 1900))

### sorting data
inc.order <- order(data$Date, decreasing = FALSE)
Expand All @@ -156,18 +177,23 @@ dateRefill.fromData <-
diff <- zoo::as.Date(data[1,2])-origin
rm(year)

days <- as.numeric((y.max-y.min+1)*365-diff)
daySum <- 0
for(x in year.list)
{
daySum <- daySum + Hmisc::yearDays(zoo::as.Date(paste(x, "-01-01", sep = "")))
}
daySum <- as.numeric(daySum - diff)

final.data[1:days,] <- NA # remove first few null days because data is not start on 1/1
final.data[,2] <- seq(data[1,2], by = "1 days", length.out = days)
final.data[1:daySum,] <- NA # remove first few null days because data is not start on 1/1
final.data[,2] <- seq(data[1,2], by = "1 days", length.out = daySum)

#### setting rownames
rownames(data) <- c(1:nrow(data))

my.index <- match(data$Date, as.POSIXlt(final.data$Date))
final.data[my.index,] <- data[,]

for(i in days:1)
for(i in daySum:1)
{
if(!is.na(final.data[i,1])){
tag <- i
Expand All @@ -187,7 +213,7 @@ dateRefill.fromData <-
}
}

final.data$Date <- as.Date(final.data$Date) # for correcting date time in excel
final.data$Date <- zoo::as.Date(final.data$Date) # for correcting date time in excel

colnames(final.data) <- colNameVector

Expand Down

0 comments on commit e2cfe51

Please sign in to comment.