In R, package xts, how would one iterate period subsetting over a list without throwing errors?
-
17-04-2021 - |
문제
Assume:
- list of n xts objects in
.GlobalEnv
with the suffix ".raw" (e.g:ABC.raw
) - have created a list of
.raw
names in alist
(ie,rawfiles <- ls(pattern="*.raw",envir=.GlobalEnv)
)
Would like to:
loop
orlapply
through rawfiles and subset a particular timeperiod in each iteration- for example, to write this as a single line would be:
new <- ABC.raw["T09:00/T10:00"]
if I wanted to subsetABC.raw
from 9am to 10am each day.
The problem is:
- Doesn't seem to be an easy way of passing
["Thh:mm/Thh:mm"]
to a loop, apply or assign without causing errors.
Any ideas how to pass this?
In pidgeon code, I guess I'm looking for a working equivalent of:
for(i in 1:length(raw)){
raw[i]["T09:00/T10:00"]
}
Many thanks in advance for any assistance on this.
해결책
Try get
.
get(x)
retrieves the variable whose name is stored in x
, so foo<-1; get('foo')
would return 1.
for ( rawname in rawfiles ) {
get(rawname)["T09:00/T10:00"]
}
제휴하지 않습니다 StackOverflow