Construct a Data Frame Object

USAGE:
data.frame( ..., row.names, check.rows = F, check.names = T,
           na.strings = "NA")

as.data.frame(object, ...) is.data.frame(object)

...:
objects to be included in the data frame. These can be vectors (numeric, character, or logical), factors, numeric matrices, lists, or other data frames. Matrices, lists, and data frames provide as many variables to the new data frame as they have columns, elements, or variables, respectively. Numeric vectors and factors are included as is, and non-numeric vectors are coerced to be factors, whose levels are the unique values appearing in the vector. Making any of the above the argument in a call to the function I() prevents the expansion or conversion.

The treatment of objects appearing in a call depends on the existence of corresponding methods for as.data.frame(); see the discussion of argument object, and the note on methods below.

row.names:
optional argument to provide the row.names attribute. If included, can either provide an explicit set of row names or indicate that one of the variables should be used as the row names. In the latter case, row.names can either be a numeric index for the variable or the name that the variable would have in the data frame. The indicated variable will be dropped as a variable and used for the row names. By default, data.frame tries to construct the row names from the dimnames attribute of a matrix argument, from the row.names argument of a previous data frame, or, if none of these produces row names, by using the row numbers. Supplying the argument explicitly as NULL forces the row numbers to be used. However the row names are constructed, they are required to be unique. Note that arguments row.names, check.rows, and check.names, if supplied, must be given by name.
check.rows:
flag; if TRUE, the rows are checked for consistency. If several arguments imply row names, the function will check that these names are consistent. Generally only useful in computations that claim to have selected the same rows from several parallel sources of data.
check.names:
flag; if TRUE, the variable names will be made into legal S object names, by replacing illegal characters, like blanks, parentheses, or commas by . (type ?make.name for details).
na.strings:
Character vector. When character valued input columns are converted from factors, values found in na.strings will be considered to be missing values. The default is "NA". character(0) means that no strings will be considered missing values.

object:
an object to be coerced to be a data frame. This object can be anything representing one or more variables of a data frame; for example, a vector representing a single column or a matrix representing as many variables as there are columns in the matrix. The interpretation of object in as.data.frame() and of the same object as one of the arguments to data.frame() is determined by the method defined for that class of objects. See the note on methods below.

VALUE:
in the case of data.frame(), a data frame consisting of all the variables supplied in the arguments. The variables are required to have the same number of observations. All the variables should have names; in the case of list arguments this is required, and in other cases data.frame will construct default names but issue a warning. The elements of the data frame are the variables. In addition, the data frame will always have an attribute "row.names" containing the row names.

In the case of as.data.frame(), the single argument will be interpreted as a data frame. Columns of a matrix and elements of a list will become individual variables. Objects inheriting from "data.frame" will be returned as is, except that any classes preceding "data.frame" will be dropped, so that "data.frame" becomes the first class.


METHODS:
The behavior of both data.frame() and as.data.frame() is determined by the methods for as.data.frame() that apply to the arguments. That is, as.data.frame() is a generic function. If object inherits from a class for which an as.data.frame method exists, the value of that method will also determine the behavior of the same object when it appears as an argument to data.frame. Less abstractly put, you can think of data.frame() as not much more than the loop: for(i in list(...)) value <- cbind(value, as.data.frame(i)) Methods exist for a number of classes, and new methods can be written to define the behavior of new classes, or to modify the existing behavior. In addition, the scope of class is extended in this case, in that for objects that do not have an explicit class in the 1992 version of S, the value of data.class(object) is used to select a method for as.data.frame(). So, for example, the method as.data.frame.character defines the behavior of character vectors as arguments to as.data.frame(). See the reference for more details and examples.

Reference:
John M. Chambers (1994) Variables in Data Frames. AT&T Bell Laboratories Statistics Research Report Number 94-2

SEE ALSO:
as.matrix.data.frame , data.frame.object , data.matrix .

EXAMPLES:
# two lists, taking one component as row names
data.frame(car.specs, car.report[-1], row.names = "Model")

# The following are roughly equivalent except for speed data.frame(scan("myfile",what=list(a=0,b=0,c="")) # Slow as.data.frame(scan("myfile",what=list(a=0,b=0,c="")) # Better read.table("myfile") # Best