Coerce an xts Object to an Environment by Column
Source:R/as.environment.xts.R
as.environment.xts.RdMethod to automatically convert an xts object to an environment containing vectors representing each column of the original xts object. The name of each object in the resulting environment corresponds to the name of the column of the xts object.
Usage
# S3 method for class 'xts'
as.environment(x)Note
Environments do not preserve (or have knowledge) of column order and cannot be subset by an integer index.
Examples
x <- xts(1:10, Sys.Date()+1:10)
colnames(x) <- "X"
y <- xts(1:10, Sys.Date()+1:10)
colnames(x) <- "Y"
xy <- cbind(x,y)
colnames(xy)
#> [1] "Y" "y"
e <- as.environment(xy) # currently using xts-style positive k
ls(xy)
#> [1] "Y" "y"
ls.str(xy)
#> Y : An xts object on 2026-03-06 / 2026-03-15 containing:
#> Data: integer [10, 1]
#> Columns: Y
#> Index: Date [10] (TZ: "UTC")
#> y : An xts object on 2026-03-06 / 2026-03-15 containing:
#> Data: integer [10, 1]
#> Columns: y
#> Index: Date [10] (TZ: "UTC")