簡體   English   中英

R中帶有對象的子集xts

[英]subset xts with object in R

對此必須有一個簡單的解決方案,但是以某種方式我找不到它。 我想通過年份(簡單)來子集一個xts對象,但是要使用另一個對象。

data <- xts(1:1000, Sys.Date()+1:1000)
data['2016',]  # this will give all 2016 data

現在,我想這樣做:

year <- as.numeric(2016)
data['year',]

顯然這行不通。 任何幫助,不勝感激

您需要一個character對象:

year <- "2016"
data[year]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM