R: Conditionally convert x to yearmon if the conversion is...
as.yearmon2
R Documentation
Conditionally convert x to yearmon if the conversion is unqique,
retaining x as names.
Description
Convert x to class "yearmon". If duplicate months are
found, return x. Otherwise, return the conversion with names =
x.
Usage
as.yearmon2(x, ...)
Arguments
x
object suitable for as.yearmon
...
additional argument(s) (e.g., a format) passed to
as.yearmon.
Details
Dates for some monthly data include the day of the month on which the
data were published. For many purposes, one would like to have the
data as a zoo object with a yearmon index, while still
retaining the full date for other purposes.
If the yearmon form of the input is not uniqe,
as.yearmon2 returns the input unchanged with a warning.
Otherwise, it returns the yearmon conversion with the input as
names.
Value
Returns either its argument or its argument converted to class
yearmon with names.
See Also
yearmon
Examples
x1 <- as.Date(c("2000-01-01", "2000-01-01"))
as.yearmon2(x1)
#Warning message:
#In as.yearmon2(x1) :
# 1 duplicate months found in 'x'; returning 'x' unchanged
x2 <- as.Date(c("2000-01-01", "2000-02-01"))
as.yearmon2(x2)
# month of x2 with names x2
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(FinTS)
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/FinTS/as.yearmon2.Rd_%03d_medium.png", width=480, height=480)
> ### Name: as.yearmon2
> ### Title: Conditionally convert x to yearmon if the conversion is unqique,
> ### retaining x as names.
> ### Aliases: as.yearmon2
> ### Keywords: ts
>
> ### ** Examples
>
> x1 <- as.Date(c("2000-01-01", "2000-01-01"))
> as.yearmon2(x1)
[1] "2000-01-01" "2000-01-01"
Warning message:
In as.yearmon2(x1) :
1 duplicate months found in 'x'; returning 'x' unchanged
> #Warning message:
> #In as.yearmon2(x1) :
> # 1 duplicate months found in 'x'; returning 'x' unchanged
>
> x2 <- as.Date(c("2000-01-01", "2000-02-01"))
> as.yearmon2(x2)
2000-01-01 2000-02-01
"Jan 2000" "Feb 2000"
> # month of x2 with names x2
>
>
>
>
>
>
> dev.off()
null device
1
>