Skip to contents

Concatenate or bind by row two or more xts objects along a time-based index. All objects must have the same number of columns and be xts objects or coercible to xts.

Usage

# S3 method for class 'xts'
c(...)

# S3 method for class 'xts'
rbind(..., deparse.level = 1)

Arguments

...

Objects to bind by row.

deparse.level

Not implemented.

Value

An xts object with one row per row for each object concatenated.

Details

Duplicate index values are supported. When one or more input has the same index value, the duplicated index values in the result are in the same order the objects are passed to rbind(). See examples.

c() is an alias for rbind() for xts objects.

See merge.xts() for traditional merge operations.

Note

rbind() is a '.Primitive' function in R, which means method dispatch occurs at the C-level, and may not be consistent with normal S3 method dispatch (see rbind() for details). Call rbind.xts() directly to avoid potential dispatch ambiguity.

See also

Author

Jeffrey A. Ryan

Examples


x <- xts(1:10, Sys.Date()+1:10)
str(x)
#> An xts object on 2026-03-06 / 2026-03-15 containing: 
#>   Data:    integer [10, 1]
#>   Index:   Date [10] (TZ: "UTC")

merge(x,x)
#>             x x.1
#> 2026-03-06  1   1
#> 2026-03-07  2   2
#> 2026-03-08  3   3
#> 2026-03-09  4   4
#> 2026-03-10  5   5
#> 2026-03-11  6   6
#> 2026-03-12  7   7
#> 2026-03-13  8   8
#> 2026-03-14  9   9
#> 2026-03-15 10  10
rbind(x,x)
#>            [,1]
#> 2026-03-06    1
#> 2026-03-06    1
#> 2026-03-07    2
#> 2026-03-07    2
#> 2026-03-08    3
#> 2026-03-08    3
#> 2026-03-09    4
#> 2026-03-09    4
#> 2026-03-10    5
#> 2026-03-10    5
#> 2026-03-11    6
#> 2026-03-11    6
#> 2026-03-12    7
#> 2026-03-12    7
#> 2026-03-13    8
#> 2026-03-13    8
#> 2026-03-14    9
#> 2026-03-14    9
#> 2026-03-15   10
#> 2026-03-15   10
rbind(x[1:5],x[6:10])
#>            [,1]
#> 2026-03-06    1
#> 2026-03-07    2
#> 2026-03-08    3
#> 2026-03-09    4
#> 2026-03-10    5
#> 2026-03-11    6
#> 2026-03-12    7
#> 2026-03-13    8
#> 2026-03-14    9
#> 2026-03-15   10

c(x,x)
#>            [,1]
#> 2026-03-06    1
#> 2026-03-06    1
#> 2026-03-07    2
#> 2026-03-07    2
#> 2026-03-08    3
#> 2026-03-08    3
#> 2026-03-09    4
#> 2026-03-09    4
#> 2026-03-10    5
#> 2026-03-10    5
#> 2026-03-11    6
#> 2026-03-11    6
#> 2026-03-12    7
#> 2026-03-12    7
#> 2026-03-13    8
#> 2026-03-13    8
#> 2026-03-14    9
#> 2026-03-14    9
#> 2026-03-15   10
#> 2026-03-15   10

# this also works on non-unique index values
x <- xts(rep(1,5), Sys.Date()+c(1,2,2,2,3))
y <- xts(rep(2,3), Sys.Date()+c(1,2,3))

# overlapping indexes are appended
rbind(x,y)
#>            [,1]
#> 2026-03-06    1
#> 2026-03-06    2
#> 2026-03-07    1
#> 2026-03-07    1
#> 2026-03-07    1
#> 2026-03-07    2
#> 2026-03-08    1
#> 2026-03-08    2
rbind(y,x)
#>            [,1]
#> 2026-03-06    2
#> 2026-03-06    1
#> 2026-03-07    2
#> 2026-03-07    1
#> 2026-03-07    1
#> 2026-03-07    1
#> 2026-03-08    2
#> 2026-03-08    1