index                  package:zoo                  R Documentation

_E_x_t_r_a_c_t_i_n_g/_R_e_p_l_a_c_i_n_g _t_h_e _I_n_d_e_x _o_f _O_b_j_e_c_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     Generic functions for extracting the index of an object and
     replacing it.

_U_s_a_g_e:

     index(x, ...)
     index(x) <- value

_A_r_g_u_m_e_n_t_s:

       x: an object.

     ...: further arguments passed to methods.

   value: an ordered vector of the same length as the '"index"'
          attribute of 'x'.

_D_e_t_a_i_l_s:

     'index' is a generic function for extracting the index of objects,
     currently it has a default method and a method for 'zoo' objects
     which is the same as the 'time' method for 'zoo' objects. Another
     pair of generic functions provides replacing the 'index' or 'time'
     attribute.  Methods are available for '"zoo"' objects only, see
     examples below.

     The start and end of the index/time can be queried by using the
     methods of 'start' and 'end'.

_S_e_e _A_l_s_o:

     'time', 'zoo'

_E_x_a_m_p_l_e_s:

     x.date <- as.Date(paste(2003, 2, c(1, 3, 7, 9, 14), sep = "-"))
     x <- zoo(rnorm(5), x.date)

     ## query index/time of a zoo object
     index(x)
     time(x)

     ## change class of index from Date to POSIXct
     ## relative to current time zone
     x
     index(x) <- as.POSIXct(format(time(x)),tz="")
     x

     ## replace index/time of a zoo object
     index(x) <- 1:5
     x
     time(x) <- 6:10
     x

     ## query start and end of a zoo object
     start(x)
     end(x)

     ## query index of a usual matrix
     xm <- matrix(rnorm(10), ncol = 2)
     index(xm)

