[R-sig-Finance] Problems subsetting zoo objects
icosa atropa
icos.atropa at gmail.com
Sat Jul 15 23:16:53 CEST 2006
Hello,
After 6 months of using both the its and the zoo packages, I've grown
fond of the zoo package, but I still struggle with subsetting
zoo objects.
I'm trying to remove outliers from my records by setting them to NA; I
can do some dataframe-type subsetting with "its" objects, but I'm
still confused about zoo's rules.
###An example -------------------
require(zoo); require(its)
my.data = data.frame(depth=c(5, 6, 30), temp=c(20, 21, 100))
my.index = as.POSIXct(c("1999-02-10", "1999-02-11", "1999-02-12"))
my.zoo = zoo(my.data, order.by=my.index)
my.its = as.its(my.zoo)
#Questions
#1 - Not supposed to work?
my.zoo$depth #NULL
my.its$zoo #NULL
dynlm(depth ~ temp, data=my.zoo) #works
my.data$depth # works
#2 - I expected the following line to return values
my.zoo[my.zoo[,1] > 10] # returns column names but no values
my.zoo[my.zoo[,1] > 10] = NA # Still, this _does_ work
my.its[my.its[,1] > 10 ] # And this returns values
my.zoo = zoo(my.data, order.by=my.index) # reset my.zoo
#3 - I try to isolate my confusion:
my.zoo[c(T,F,F),1] == 5 # True
my.zoo[c(T,F,F),2] == 20 # True
my.zoo[c(T,F,F),1:2] == 5 # True. Why not ==c(5,20)?
#i.e.
my.zoo[c(T,F,F),1:2] == my.zoo[c(T,F,F),c(T,F)] #True
my.zoo[c(T,F,F),1:2] == my.zoo[c(T,F,F),c(F,T)] #False
my.zoo[c(F,F,T), c(T,F)] == my.zoo[c(F,F,T), c(T,T)] #True
#End of Example---------------------------------
I'd greatly appreciate any insights or suggests.
Thanks in advance,
Christian Gunning
Masters Student
University of New Mexico
Dept of Water Resources
More information about the R-SIG-Finance
mailing list