我是R新手。我有一個數據索引的onject,需要過濾以便我可以獲取每個第X個數據點。我如何去做這件事?用於創建數據 代碼爲:篩選R中的數據索引對象中的行
temp <- blpGetData(conn, securities[1], fields=values,start=startdate,end=enddate, barsize=interval, barfields=tick,retval=datatype)
assign(paste(gsub(" +","",repl[1])),temp)
name <- paste("merge(",paste(gsub(" +","",repl[1])))
suf <- paste(", suffixes=c('.",paste(gsub(" +","",repl[1])),"'",sep="")
for(i in 2:length(securities)){
temp <- blpGetData(conn, securities[i],
fields=values,
start=startdate,
end=enddate,
barsize=interval,
barfields=tick,
retval=datatype)
assign(paste(gsub(" +","",repl[i])),temp)
name <- paste(name,",",paste(gsub(" +","",repl[i])))
suf <- paste(suf,",'.",paste(gsub(" +","",repl[i])),"'",sep="")
}
name <- paste(name,suf,"))")
mat <- eval(parse(text=name))
我希望每一個X行。 mat
是對象。
> cat(name)
PX_OPEN..CINC1 PX_HIGH..CINC1 PX_LOW..CINC1 PX_LAST..CINC1 PX_OPEN..CINC5 PX_HIGH..CINC5 PX_LOW..CINC5 PX_LAST..CINC5 PX_OPEN..UST10Y PX_HIGH..UST10Y PX_LOW..UST10Y PX_LAST..UST10Y
> str(mat) ‘zoo’ series from 2011-11-11 to 2012-01-18
Data: num [1:49, 1:12] 206 205 205 212 219 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:12] "PX_OPEN..CINC1" "PX_HIGH..CINC1" "PX_LOW..CINC1" "PX_LAST..CINC1"
... Index: Date[1:49], format: "2011-11-11" "2011-11-14" "2011-11-15" "2011-11-16" "2011-11-17" "2011-11-18" ...
你可以做'貓(名稱)'和'STR(墊)'請嗎? - 只是有助於弄清楚發生了什麼。乾杯! – 2012-01-19 01:58:27
cat(name) PX_OPEN..CINC1 PX_HIGH..CINC1 PX_LOW..CINC1 PX_LAST..CINC1 PX_OPEN..CINC5 PX_HIGH..CINC5 PX_LOW..CINC5 PX_LAST..CINC5 PX_OPEN..UST10Y PX_HIGH..UST10Y PX_LOW..UST10Y PX_LAST..UST10Y> > str(mat) 'zoo'series from 2011-11-11 to 2012-01-18 Data:num [1:49,1:12] 206 205 205 212 219 ... - attr(*,「dimnames」)=列表2 .. $:NULL .. $:chr [1:12]「PX_OPEN..CINC1」「PX_HIGH..CINC1」「PX_LOW..CINC1」「PX_LAST ..CINC1「... 指數:日期[1:49],格式:」2011-11-11「」2011-11-14「」2011-11-15「」2011-11-16「」「2011- 11-17「」2011-11-18「... – 2012-01-19 02:36:44