Last data update: 2014.03.03

R: CreateOriginPeriods
CreateOriginPeriodsR Documentation

CreateOriginPeriods

Description

This will create a set of origin period values

Usage

  CreateOriginPeriods(OriginStart, OriginEnd = NULL,
    OriginLength = years(1), StartDay = 1, StartMonth = 1,
    Verbose = FALSE)

Arguments

OriginStart

Either a vector of date-time objects, or a vector of numbers indicating the year.

OriginEnd

A vector of date-time objects. If this argument is supplied, it is assumed that OriginStart contains date-time objects.

OriginLength

A Period object. These are easily created as shown in the example below. The default is a period of one year. If OriginStart and OriginEnd are supplied, this argument is ignored.

StartDay

If OriginStart and OriginEnd are supplied, this argument is ignored.

StartMonth

If OriginStart and OriginEnd are supplied, this argument is ignored.

Verbose

Boolean indicating whether or not to display warning messages.

Details

If the triangle dataframe does not have lubridate intervals, they must be created. Origin periods may be established one of three ways: 1. The origin periods are passed in as POSIX dates. This is a simple matter of forming the interval using lubridate. 2. The origin periods are passed in with a start date, but no end date. We need to have a common period to establish the end date. 3. The origin periods are passed in as parts of a date. This will typically happen if we know the year, but not the month or day. In this case , the user may pass in month and day values

Value

A vector of intervals

See Also

CreateDevelopmentLags, CreateEvaluationDates

Examples

# Case 1
library(lubridate)
OriginStart = c(mdy("1/1/2000"), mdy("1/1/2000"), mdy("1/1/2001"))
OriginEnd = c(mdy("12/31/2000"), mdy("12/31/2000"), mdy("12/31/2001"))

OriginPeriods = CreateOriginPeriods(OriginStart, OriginEnd)
OriginPeriods

# Case 2
OriginStart = c(mdy("1/1/2000"), mdy("1/1/2000"), mdy("1/1/2001"))
OriginPeriods = CreateOriginPeriods(OriginStart, OriginLength = months(12))
OriginPeriods

# Case 3
OriginStartYear = c(2000, 2000, 2001)
OriginPeriods = CreateOriginPeriods(OriginStartYear, OriginLength = years(1)
                                     , StartDay = 1, StartMonth = 1)
OriginPeriods

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(MRMR)
Loading required package: reshape2
Loading required package: ggplot2
Loading required package: lubridate

Attaching package: 'lubridate'

The following object is masked from 'package:base':

    date

Loading required package: lmtest
Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Loading required package: plyr

Attaching package: 'plyr'

The following object is masked from 'package:lubridate':

    here

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MRMR/CreateOriginPeriods.Rd_%03d_medium.png", width=480, height=480)
> ### Name: CreateOriginPeriods
> ### Title: CreateOriginPeriods
> ### Aliases: CreateOriginPeriods
> 
> ### ** Examples
> 
> # Case 1
> library(lubridate)
> OriginStart = c(mdy("1/1/2000"), mdy("1/1/2000"), mdy("1/1/2001"))
> OriginEnd = c(mdy("12/31/2000"), mdy("12/31/2000"), mdy("12/31/2001"))
> 
> OriginPeriods = CreateOriginPeriods(OriginStart, OriginEnd)
Error in OriginPeriodFromDates(OriginStart, OriginEnd) : 
  OriginStart and OriginEnd were supplied, but OriginStart is not a POSIXct or POSIXt class variable.
Calls: CreateOriginPeriods -> OriginPeriodFromDates
Execution halted