[R-sig-Finance] Problems subsetting zoo objects
Gabor Grothendieck
ggrothendieck at gmail.com
Sun Jul 16 01:27:20 CEST 2006
$ is not valid. zoo is modelled on ts which also
does not support $.
In the case of logical subscripting its a bug. (Thanks.)
It will be fixed. In the interim do it this way:
my.zoo[which(my.zoo[,1] > 10),]
my.zoo[which(my.zoo[,1] > 10),] <- NA
On 7/15/06, icosa atropa <icos.atropa at gmail.com> wrote:
> 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