简体   繁体   中英

Finding the max of Zoo object in R

I have z - zoo object of time series. Its str description is:

> str (z)
‘zoo’ series from 2014-11-26 13:00:00 to 2015-03-01
  Data: Named num [1:2152] 0 0.07 0.07 0.05 0.06 0.02 0.04 0.02 0.02 0.01 ...
 - attr(*, "names")= chr [1:2152] "1" "2" "3" "4" ...
  Index:  POSIXct[1:2152], format: "2014-11-26 13:00:00" "2014-11-26 14:00:00" "2014-11-26 15:00:00" "2014-11-26 16:00:00" .. 

I would like to find the maximum values in the series:

> which.max(z)
272 
272

I get twice the same number 272. I think it is because of the - attr(*, "names") When I use the following:

> mx <- z[which.max(z)]
> mx
2014-12-07 20:00:00 
                0.1 
> coredata(mx)
272 
0.1 

I would like to get just the value of 0.1 instead of 272 and 0.1

Thanks to @Pierre Lafortune The solution is:

> unname(coredata(mx))
[1] 0.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM