as.data.frame              package:base              R Documentation

_C_o_e_r_c_e _t_o _a _D_a_t_a _F_r_a_m_e

_D_e_s_c_r_i_p_t_i_o_n:

     Functions to check if an object is a data frame, or coerce it if
     possible.

_U_s_a_g_e:

     as.data.frame(x, row.names = NULL, optional = FALSE)
     is.data.frame(x)

_A_r_g_u_m_e_n_t_s:

       x: any R object.

row.names: 'NULL' or a character vector giving the row names for the
          data frame.  Missing values are not allowed.

optional: logical. If 'TRUE', setting row names and converting column
          names (to syntactic names) is optional.

_D_e_t_a_i_l_s:

     'as.data.frame' is a generic function with many methods, and users
     and packages can supply further methods.

     If a list is supplied, each element is converted to a column in
     the data frame.  Similarly, each column of a matrix is converted
     separately. This can be overridden if the object has a class which
     has a method for 'as.data.frame': two examples are matrices of
     class '"model.matrix"' (which are included as a single column) and
     list objects of class '"POSIXlt"' which are coerced to class
     '"POSIXct"'.

     As from R 1.9.0 arrays can be converted.  One-dimensional arrays
     are treated like vectors and two-dimensional arrays like matrices.
      Arrays with more than two dimensions are converted to matrices by
     'flattening' all dimensions after the first and creating suitable
     column labels.

     Character variables are converted to factor columns unless
     protected by 'I'.

     If a data frame is supplied, all classes preceding '"data.frame"'
     are stripped, and the row names are changed if that argument is
     supplied.

     If 'row.names = NULL', row names are constructed from the names or
     dimnames of 'x', otherwise are the integer sequence starting at
     one.  Few of the methods check for duplicated row names. Names are
     removed from vector columns unless 'I'.

_V_a_l_u_e:

     'as.data.frame' returns a data frame, normally with all row names
     '""' if 'optional = TRUE'.

     'is.data.frame' returns 'TRUE' if its argument is a data frame
     (that is, has '"data.frame"' amongst its classes) and 'FALSE'
     otherwise.

_N_o_t_e:

     In versions of R prior to 1.4.0 logical columns were converted to
     factors (as in S3 but not S4).

_R_e_f_e_r_e_n_c_e_s:

     Chambers, J. M. (1992) _Data for models._ Chapter 3 of
     _Statistical Models in S_ eds J. M. Chambers and T. J. Hastie,
     Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     'data.frame', 'as.data.frame.table' for the 'table' method (which
     has additional arguments if called directly).

