Time Series Base Package Xts_r language

Source: Internet
Author: User
Tags diff print object time interval

Bibliography: "XTs ideal of R"--Introduction to the tool article

XTS is an extended implementation of time series data (Zoo), which aims to unify the operation interface of time series. In fact, the XTS type inherits the zoo type, enriches the function of time series data processing, the API definition is more close to the user and more practical. XTS data structure

The XTS extends the zoo infrastructure, which consists of 3 parts, as shown in Figure 2-7.

Index part: The time type vector.

Data section: A matrix based type that supports any type that can be converted to and from a matrix.

Properties section: Attachment information, including the time zone and index time type formats, and so on. XTSAPI Introduction

(1) XTS Foundation

XTS: Defines XTS data types, inheriting zoo types.

Coredata.xts: View or edit the data portion of the XTs object.

Xtsattributes: View or edit the Properties section of the XTs object.

Dimnames.xts: View or edit the XTS dimension name.

Sample_matrix: Test dataset, including records of 180 xts objects, matrix type.

Xtsapi:c Language API interface.

(2) Type conversion

As.xts: Convert object to XTS (zoo) type.

As.xts.methods: Converts objects to xts functions.

PLOT.XTS: Provides XTS interface mapping for the plot function.

. parseISO8601: The string (ISO8601 format) is exported as a POSIXCT type, including the list object for the start time and end time.

Firstof: Create a start time, Posixct type.

Lastof: Create an end time, Posixct type.

Indexclass: Index type.

. Indexdate: Date of index.

. Indexday: index date, same. Indexdate.

. Indexyday: The Year (day) value of the index.

. Indexmday: The month (day) value of the index.

. Indexwday: The Week (day) value of the index.

. Indexweek: The week value of the index.

. Indexmon: The monthly value of the index.

. Indexyear: The year value of the index.

. Indexhour: The value of the index.

. Indexmin: The score of the index.

. INDEXSEC: The second value of the index.

(3) Data processing

Align.time: One of the following time alignment data, seconds, minutes, hours.

Endpoints: Extracts index data by time unit.

Merge.xts: Merges multiple XTS objects and overrides the Zoo::merge.zoo function.

Rbind.xts: Data is merged by row, providing a XTS interface for the Rbind function.

Split.xts: Data segmentation, for the Split function, provides XTS interface.

Na.locf.xts: Replaces the NA value and overrides the ZOO:NA.LOCF function.

(4) Data statistics

Apply.daily: Split data by day, execute function.

Apply.weekly: Splits the data by the week, executes the function.

Apply.monthly: Divides data by month, executes function.

Apply.quarterly: Split data by quarter, execute function.

Apply.yearly: Split data by year, execute function.

To.period: Splits data by period.

Period.apply: Performs custom functions by period.

Period.max: Calculates the maximum value by period.

Period.min: Calculates the minimum value by period.

Period.prod: Calculates the index by period.

Period.sum: Sum by period.

Nseconds: How many seconds are included in the calculation dataset.

Nminutes: How many points are included in the calculation data set.

Nhours: Calculate how many data sets are included.

Ndays: How many days are included in the calculation data set.

Nweeks: Calculates how many weeks the dataset includes.

Nmonths: How many months are included in the calculation data set.

Nquarters: Calculates how many seasons the dataset includes.

Nyears: How many years are the data sets included in the calculation.

Periodicity: View the period of the time series.

(5) Auxiliary tools

First: Sets a subset of conditions from start to finish.

Last: Sets a subset of conditions from end to start.

Timebased: Judge whether it is a time type.

TIMEBASEDSEQ: The sequence in which the time is created.

Diff.xts: Calculates step size and difference.

Isordered: Check whether the vectors are sequential.

Make.index.unique: Forced time only, increase millisecond random number.

Axticksbytime: Calculates the x-axis tick mark position by a time description.

Indextz: Queries the time zone of the XTs object.
#xts使用
# #基本操作

> sample.xts <-as.xts (Sample_matrix, descr= ' My new XTs object ')  
                     # Create a XTs object and set properties Descr  
> class ( sample.xts)  # xts is an inherited Zoo type Object  
[1] "xts" "Zoo"  

> str (sample.xts)    # Print Object structure an  
' xts ' object on 2007-01-02/2007-06-30 containing:  
  data:num [1:180, 1:4] 50.2 50.4 50.4 50.2 ...  
 -attr (*, "dimnames") =list of 2  
  . $: NULL   #行名
  . $: CHR [1:4] ' Open ' ' High ' ' low ' ' Close '  # column name
  Indexed by objects of class: [Posixct,posixt] TZ:  
  xts Attri Butes:  
List of 1  
 $ DESCR:CHR "My new XTs object"  #描述

> attr (sample.xts, ' descr ')  # View the properties of an object descr  
In [], XTS data queries are done through string matching.
> Head (sample.xts[' 2007 ']) # Select 2007 Years of data Open high low close 2007-01-02 50.03978 50.117 78 49.95041 50.11778 2007-01-03 50.23050 50.42188 50.23050 50.39767 2007-01-04 50.42096 50.42096 50.26414 50.33236 2 007-01-05 50.37347 50.37347 50.22103 50.33459 2007-01-06 50.24433 50.24433 50.11121 50.18112 2007-01-07 50.13211 50.21 561 49.99185 49.99185 > Head (sample.xts[' 2007-03/') # Select March 2007 Data Open high-low Clo  Se 2007-03-01 50.81620 50.81620 50.56451 50.57075 2007-03-02 50.60980 50.72061 50.50808 50.61559 2007-03-03 50.73241 50.73241 50.40929 50.41033 2007-03-04 50.39273 50.40881 50.24922 50.32636 2007-03-05 50.26501 50.34050 50.26501 50.29   
               567 2007-03-06 50.27464 50.32019 50.16380 50.16380 > Head (sample.xts[' 2007-03-06/2007 ']) # data from March 06, 2007 to 2007 Open High Down close 2007-03-06 50.27464 50.32019 50.16380 50.16380 2007-03-07 50.14458 5 0.20278 49.91381 49.91381 2007-03-08 49.93149 50.00364 49.84893 49.91839 2007-03-09 49.92377 49.92377 49.74242 49.80712 2007-03-10 49.79370 49.88984 49.70385 49.88698 2007-03-11 49.83062 49.88295 49.76031 49.78806 > sample.xts[' 2007-01-03 '] # January 2007  Data Open on 03th
Drawing with XTs objects

With XTS objects you can draw graphs and chart, here's the code that produces the two graphs, first the graphs:

> Data (Sample_matrix)  
> Plot (as.xts (Sample_matrix)) Warning message: In Plot.xts (as.xts (  
Sample_ MATRIX): Only the  
  univariate series would be plotted

Warning messages indicate that only a single variable sequence will be drawn, that is, only the curve of the first column of data sample_matrix[,1] is drawn.

Chart

Plot (As.xts (Sample_matrix), type= ' candles ')  #画K线图


Better financial plots can is found in the Quantmod package, though this are generally the incompatible with standard R graph ICS Tools. The XTs object's type conversion creates the End-to-end function Firstof () and Lastof ()

> Firstof  # 2000 The first day of the year, when the minutes and seconds show omitted  
[1] "2000-01-01 CST"  
> Firstof (2005,01,01)  
[1] "2005-01-01 CST "  
> Lastof (2007)  # 2007 The last day of the year, the last second  
[1]" 2007-12-31 23:59:59.99998 CST "  
> Lastof (2007,10)  
[1] "2007-10-31 23:59:59.99998 CST" 

> parseISO8601 ('% ')  # in ISO8601 format, created 2000 end to end time  
$ First.time  
[1] "2000-01-01 CST"  
$last. Time  
[1] "2000-12-31 23:59:59.99998 CST"  

>. parseISO8601 (' 2000-05/2001-02 ')  
# in ISO8601 format, created May 2000, the end of February 2001  
$first. Time  
[1] " 2000-05-01 CST "  
$last. Time  
[1]" 2001-02-28 23:59:59.99998 CST "  

> parseISO8601 (' 2000-01/02 ')  
$first.  
time [1] "2000-01-01 CST"  
$last. Time  
[1] "2000-02-29 23:59:59.99998 CST"  

> parseISO8601 (' t08:30/t15:0 0 ')  
$first. Time  
[1] "1970-01-01 08:30:00 CST"  
$last. Time  
To create a XTs object with a time type index
> x <-timebasedseq (' 2010-01-01/2010-01-02 12:00 ')  # Create Posixt type Time  
> head (x)  
[1] "2010-01-01 00:00:00 CST "  
[2]" 2010-01-01 00:01:00 CST "  
[3]" 2010-01-01 00:02:00 CST "  
[4]" 2010-01-01 00:03:00 CST "  
[5] "2010-01-01 00:04:00 CST"  
[6] "2010-01-01 00:05:00 CST"  
> Class (x)  
[1] "Posixt"  "Posixct"  
> x <-xts (1:length (x), x)   # Create XTS Objects  
> Head (x)  
                    [, 1]  
2010-01-01 00:00:00    1  
2010-01-01 00:01:00    2  
2010-01-01 00:02:00    3  
2010-01-01 00:03:00    4  
2010-01-01 00:04:00    5  
2010-01-01 00:05:00    6  
> Indexclass (x)  
[1] "Posixt"  "Posixct "
Display of formatted index time
> Indexformat (x) <-"%y-%b-%d%h:%m:%os3"  # Show time by regular format index  
> head (x)  
                          [, 1]  
2010-1 months-01 00:00:00.000    1  
2010-1 months -01 00:01:00.000    2  
2010-1 month -01 00:02:00.000    3  
2010-1 Month-01 00:03:00.000    4  
2010-1 months -01 00:04:00.000    5  
2010-1 months-01 00:05:00.000    
Viewing index time
> Indexhour (Head (x))  # Indexed by the hour  
[1] 0 0 0 0 0 0  
>. Indexmin (Head (x))   # index time by minutes  
Data-processing data alignment for XTS objects
x <-sys.time () + 1:30  
> Align.time (x, #整10秒对齐)    , integer times 10 in seconds  
 [1] "2013-11-18 15:42:30 CST" "2013-11-18 15:42:30 CST "  
 [3]" 2013-11-18 15:42:30 CST "2013-11-18 15:42:40 CST"  
 [5] "2013-11-18 15:42:40 CST" "2013-11-18 15 : 42:40 CST "  
 [7]" 2013-11-18 15:42:40 CST "2013-11-18 15:42:40 CST"  
 [+] "2013-11-18 15:43:00 CST" "2013-11-18 1 5:43:00 CST "  

> Align.time (x, 0)    #整60秒对齐, with a second bit for an integer  
 [1]" 2013-11-18 15:43:00 CST "2013-11-18  15:43:00 CST "  
 [3]" 2013-11-18 15:43:00 CST "2013-11-18 15:43:00 CST"  
 [5] "2013-11-18 15:43:00 CST" "2013-11-18  15:43:00 CST "  
 [7]" 2013-11-18 15:43:00 CST "2013-11-18 15:43:00 CST"  
 [9] "2013-11-18 15:43:00 CST" "2013-11-18 15:43:00 CST "  
Divide the data by time and compute
Xts.ts <-xts (Rnorm (231), as. Date (13514:13744,origin= "1970-01-01"))  
> apply.monthly (Xts.ts,mean)  # Monthly mean value, displayed on the last day of the month  
                  [, 1]  
2007-01-31  0.17699984  
2007-02-28  0.30734220  
2007-03-31-0.08757189  2007-04-30 0.18734688  
2007-05-31  0.04496954  
2007-06-30  0.06884836  
2007-07-31  0.25081814  
2007-08-19-0.28845938  
> apply.monthly (xts.ts,function (x) var (x))  
# Calculates the Custom function (variance) on a monthly basis, displayed on the last day of the month  
                [, 1]  
2007-01-31 0.9533217  
2007-02-28 0.9158947  
2007-03-31 1.2821450  
2007-04-30 1.2805976  
2007-05-31 0.9725438  
2007-06-30 1.5228904 2007-07-31 0.8737030 2007-08-19 0.8490521  
> Apply.quarterly (Xts.ts,mean)  # Calculates the mean on a quarterly basis, shown on the last day of each quarter  
                 [, 1]  
2007-03-31 0.12642053  
2007-06-30 0.09977926  
2007-08-19 0.04589268  

> Apply.yearly (xts.ts,mean)  # Average per year, shown on the last day of the year  
                 [, 1]  
Split data by interval using the To.period () function
> Data (Sample_matrix) > To.period (sample_matrix) # The default monthly segmentation matrix data Sample_matrix. Open Sample_matrix. High Sample_matrix. Low Sample_matrix. Close 2007-01-31 50.03978 50.77336 49.76308 50.22578 2007-02-28 50.2          2448 51.32342 50.19101 50.77091 2007-03-31 50.81620 50.81620 48.23648 48.97490 2007-04-30 48.94407 50.33781 48.80962 49.33974 20           07-05-31 49.34572 49.69097 47.51796 47.73780 2007-06-30 47.74432 47.94127 47.09144 47.76719 > class (To.period (Sample_matrix)) [1] "Matrix" > Samplext S <-as.xts (Sample_matrix) # Default to monthly split xts type data > To.period (samplexts) samplexts. Open samplexts. High samplexts. Low samplexts.   Close 2007-01-31 50.03978 50.77336 49.76308 50.22578 2007-02-28    50.22448 51.32342 50.19101 50.77091 2007-03-31 50.81620 50.81620 48.23648 48.97490 2007-04-30 48.94407 50.33781 48.80962 49.33974 2007-05-31 49.34572 49.690 47.51796 47.73780 2007-06-30 47.74432 47.94127 47.09144 47.76719 > class (To.  Period (samplexts)) [1] "xts" "Zoo"
Split index data by interval using the endpoints () function
> Data (Sample_matrix)  
> Endpoints (Sample_matrix)  # Default monthly Split  
[1]   0  89 119 150 180  
> Endpoints (Sample_matrix, ' days ', k=7)  # per 7th  
 [1]   0   6  27  118  
[20] 132 139 in a-I-TB 146 153 160 167 174 180  

> Endpoints (Sample_matrix, ' weeks ')     # Split by week  
 [1]   0   7  21  the  119 126  
[20], 112, the 140 147 154 161 175 180  

> Endpoints (Sample_matrix, ' months ')    # Monthly Split  
[1]   0  58  
Merging data by using the merge () function, merging by column
> (x <-xts (4:10, Sys.date () +4:10))     # create 2 xts Datasets  
           [, 1]  
2013-11-22    4  
2013-11-23    5  
2013-11-24    6  
2013-11-25    7  
2013-11-26    8  
2013-11-27    9  
2013-11-28   10  
> (y <-xts (1:6, Sys.date () +1:6))  
           [, 1]  
2013-11-19    1  
2013-11-20    2  
2013-11-21    3  
2013-11-22    4  
2013-11-23    5  
2013-11-24    6  

> Merge (x,y)  # merge data by column, empty entry to fill in Na  
            x  y  
2013-11-19 na  1  
2013-11-20 na  2  
2013-11-21 na  3  
2013-11-22  4  4  
2013-11-23  5  5  
2013-11-24  6  6  
2013-11-25  7 na  
2013-11-26  8 na  
2013-11-27  9 na  
2013-11-28 NA  

> Merge (x,y, join= ' inner ')  #按索引合并数据  
           x y  
2013-11-22 4 4  
2013-11-23 5 5  
2013-11-24 6 6  

> merge (x,y, join= ' left ')  #以左侧为基础合并数据  
            x  y  
2013-11-22  4  4  
2013-11-23  5  5  
2013-11-24  6  6  
2013-11-25  7 NA  
2013-11-26  8 Na  
2013-11-27  9 na  
Slice using the split () function, slice by row
> Data (Sample_matrix)  
> x <-as.xts (Sample_matrix)  

> Split (x) [[1]]  # Default monthly slices, print one-month data  
               Open High Low close  
2007-01-02 50.03978 50.11778 49.95041 50.11778  
2007-01-03 50.23050 50.42188 50.23050 50.39767  
2007-01-04 50.42096 50.42096 50.26414 50.33236  
2007-01-05 50.37347 50.37347 50.22103 50.33459  
2007-01-06 50.24433 50.24433 50.11121 50.18112  
2007-01-07 50.13211 50.21561 49.99185 49.99185 2007-01-08 50.03555 50.10363 49.96971 49.98806  

> Split (x, f= "weeks") [[1]]  # by week slice, print first 1 weeks data  
               Open     High down close  
2007-01-02 50.03978 50.11778 49.95041 50.11778  
2007-01-03 50.23050 50.42188 50.23050 50.39767  
2007-01-04 50.42096 50.42096 50.26414 50.33236  
2007-01-05 50.37347 50.37347 50.22103 50.33459  
2007-01-06 50.24433 50.24433 50.11121 50.18112  
2007-01-07 50.13211 50.21561 49.99185 49.99185 2007-01-08 50.03555 50.10363 49.96971 49.98806  
Na value processing
> x <-xts (1:10, Sys.date () +1:10)  
> X[c (1,2,5,9,10)] <-na  
> x  
           [, 1]  
2013-11-19   na  
2013-11-20   Na  
2013-11-21    3  
2013-11-22    4  
2013-11-23   na  
2013-11-24    6  
2013-11-25    7  
2013-11-26    8  
2013-11-27   na  
2013-11-28   na  

> Na.locf (x)  # Take na the previous one, replace Na value  
           [, 1]  
2013-11-19   na  
2013-11-20   na  
2013-11-21    3  
2013-11-22    4  
2013-11-23    4  
2013-11-24    6  
2013-11-25    7  
2013-11-26    8  
2013-11-27    8  
2013-11-28    8  

> NA.LOCF (x, fromlast=true)  #取NA后一个, replace na value  
           [, 1]  
2013-11-19    3  
2013-11-20    3  
2013-11-21    3  
2013-11-22    4  
2013-11-23    6  
2013-11-24    6  
2013-11-25    7  
2013-11-26    8  
2013-11-27   NA  
2013-11-28   
XTS The data statistics of the object to calculate the start time and end time of the XTs object
> Xts.ts <-xts (Rnorm (231), as. Date (13514:13744,origin= "1970-01-01"))  
> Start (xts.ts)  # Take starting Time  
[1] "2007-01-01"  
> End (xts.ts  # Fetch End Time  
[1] "2007-08-19"  
> Periodicity (xts.ts)  # in days, print start and end time daily periodicity from  
2007-01-01 to 2007-08-19
Calculation time interval
> Data (Sample_matrix)  
> Ndays (Sample_matrix)  # Calculate how many days  
[1] 180  
> Nweeks (Sample_matrix)  # Calculate how many weeks  
the data is [1]  
> Nmonths (Sample_matrix)  # Calculate how many months  
[1] 6  
> Nquarters (sample_matrix)  # Calculate how many seasons  
[1] 2  
> Nyears (sample_matrix)  # Calculation data How many years  
Calculate statistical indicators by period
> Zoo.data <-Zoo (rnorm) +10,as. Date (13514:13744,origin= "1970-01-01")) > EP <-Endpoints (Zoo.data, ' weeks ') # per week obtained period index > EP [1] 0 7 1 4 21 28 35 42 49 56 63 70 77 84 91 98 105 112 [119] 19 126 133-140 147 154 161 168 175 182 189 196 203 210 224 231 > period.apply (zoo.data, Index=ep, fun=function (x) mean (x)) # Calculate the mean value of the week 2007-01-07 2007-01-14 2007-01-21   
2007-01-28 2007-02-04 2007-02-11 2007-02-18 10.200488 9.649387 10.304151 9.864847 10.382943 9.660175 9.857894 2007-02-25 2007-03-04 2007-03-11 2007-03-18 2007-03-25 2007-04-01 2007-04-08 10.495037 9.569531 10.292899 9.651 616 10.089103 9.961048 10.304860 2007-04-15 2007-04-22 2007-04-29 2007-05-06 2007-05-13 2007-05-20 2007-05-27 9. 658432 9.887531 10.608082 9.747787 10.052955 9.625730 10.430030 2007-06-03 2007-06-10 2007-06-17 2007-06-24 200 7-07-01 2007-07-08 2007-07-15 9.814703 10.224869 9.509881 10.187905 10.229310 10.261725 9.85572007-07-29 2007-07-22 2007-08-05 2007-08-12 2007-08-19 9.445072 10.482020 9.844531 10.200488 9.649387 T Head (Period.max (Zoo.data, INDEX=EP)) # Calculates the maximum value of the week [, 1] 2007-01-07 12.05912 2007-01-14 10.79286 2007-0 1-21 11.60658 2007-01-28 11.63455 2007-02-04 12.05912 2007-02-11 10.67887 > Head (period.min zoo.data, INDEX=ep ) # Calculates the minimum value of the week [, 1] 2007-01-07 8.874509 2007-01-14 8.534655 2007-01-21 9.069773 2007-01-28 8.46155 5 2007-02-04 9.421085 2007-02-11 8.534655 > Head (Period.prod (Zoo.data)) # calculates an exponential value for the week [ , 1] 2007-01-07 11140398 2007-01-14 7582350 2007-01-21 11930334 2007-01-28 8658933 2007-02-04 12702505 2007-0  2-11 7702767
Time series operation check time type of XTs object
> Class (Sys.time ()) timebased (Sys.time ())  # Sys.time () is the time type Posixct  
[1] "Posixct" "Posixt"  
[1] TRUE  

> Class (Sys.date ()); timebased (Sys.date ())  # sys.date () is the time type date  
[1] "Date"  
[1] TRUE  

> Class (20070101); timebased (20070101)  # 20070101 is not a time type  
[1] "Numeric"  
[1] FALSE
Create a time series using the Timebasedseq () function
> timebasedseq (' 1999/2008 ') # per year [1] "1999-01-01" "2000-01-01" "2001-01-01" "2002-01-01" "2003-01-01" [6] "2004 -01-01 "" 2005-01-01 "" 2006-01-01 "" 2007-01-01 "" 2008-01-01 "> Head (Timebasedseq (' 199901/2008 ')) # per month [1]" December 199 8 "" January 1999 "" Hile 1999 "" March 1999 "" April 1999 "[6]" May 1999 "> Head (Timebasedseq (' 199901/2008/d '), 40) # by day [ 1] "December 1998" "January 1999" "January 1999" "January 1999" "January 1999" [6] "January 1999" "January 1999" "January 1999" "January 1999" "January 199"   9 "[11]" January 1999 "" January 1999 "" January 1999 "" January 1999 "" January 1999 "[16]" January 1999 "" January 1999 "" January 1999 "" January 1999 "  "January 1999" [21] "January 1999" "January 1999" "January 1999" "January 1999" "January 1999" [26] "January 1999" "January 1999" "January 1999" "Month 1999 "" January 1999 "[31]" January 1999 "" January 1999 "" Hile 1999 "" Hile 1999 "" Hile 1999 "[36]" Hile 1999 "" Hile 1999 "" Hile 199 9 "" Hile 1999 "" February 1999 "> Timebasedseq (' 20080101 0830 ', length=100) # created in quantity, 100 minutes of data set $from [1]" 2008-01-01 0 8:30:00 CST "$to [1] NA $by [1] "mins" $length. Out [1] 100 
Data by index () and last ()
> x <-xts (1:100, Sys.date () +1:100)  
> Head (x)  
           [, 1]  
2013-11-19    1  
2013-11-20    2  
2013-11-21    3  
2013-11-22    4  
2013-11-23    5  
2013-11-24    6  

> A (x)  # Take the first 10 data  
           [, 1]  
2013-11-19    1  
2013-11-20    2  
2013-11-21    3  
2013-11-22    4  
2013-11-23    5  
2013-11-24    6  
2013-11-25    7  
2013-11-26    8  
2013-11-27    9  
2013-11-28  

> A (x, ' 1 day ')    # take 1 days of data  
           [, 1]  
2013-11-19    1  
> Last (x, ' 1 weeks ')  # take the final 1 weeks of data  
           [, 1  
]   2014-02-24  
2014-02-25  
2014-02-26  100
Calculate step lag () and differential diff ()
> x <-xts (1:5, Sys.date () +1:5)  
> Lag (x)  # with 1 as step length  
           [, 1]  
2013-11-19   NA  
2013-11-20    1  
2013-11-21    2  
2013-11-22    3  
2013-11-23    4  
> Lag (x, K=-1, Na.pad=false)  # Take 1 as the step and remove the NA value  
           [, 1]  
2013-11-19    2  
2013-11-20    3  
2013-11-21    4  
2013-11-22    5  

> diff (x)   # 1-Order Difference  
           [, 1]  
2013-11-19   NA  
2013-11-20    1  
2013-11-21    1  
2013-11-22    1  
2013-11-23    1  
> diff (x, lag=2)  # 2-Order Difference  
           [, 1]  
2013-11-19   na  
2013-11-20   na  
2013-11-21    2  
2013-11-22    2  
2013-11-23    
Use the isordered () function to check if vectors are sorted well
> isordered (1:10, Increasing=true)  
[1] TRUE  
> isordered (1:10, Increasing=false)  
[1] FALSE  
> isordered (C (1,1:10), increasing=true)  
[1] FALSE  
> isordered (C (1,1:10), Increasing=true, strictly= FALSE)  
Use the Make.index.unique () function to force a unique index
> x <-xts (1:5, as. Posixct ("2011-01-21") + C (1,1,1,2,3)/1e3)  
> x  
                        [, 1]  
2011-01-21 00:00:00.000    1  
2011-01-21 00:00:00.000    2  
2011-01-21 00:00:00.000    3  
2011-01-21 00:00:00.002    4  
2011-01-21 00:00:00.003    5  
> Make.index.unique (x)  # increases millisecond precision to ensure index uniqueness  
                           [, 1]  
2011-01-21 00:00:00.000999    1  
2011-01-21 00:00:00.001000    2  
2011-01-21 00:00:00.001001    3  
2011-01-21 00:00:00.002000    4  
2011-01-21 00:00:00.003000    5
Query XTs object Time zone
> x <-xts (1:10, Sys.date () +1:10)  
> Indextz (x)  # time zone Query  
[1] "UTC"  
> Tzone (x)  
[1] "  UTC "  
> str (x) an  
' XTs ' object on 2013-11-19/2013-11-28 containing:  
  data:int [1:10, 1] 1 2 3 4 5 6 7 8 9  
  Indexed by objects of class: [Date] TZ:UTC  
  xts Attributes:  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.