data.frame
Construct a Data Frame

Description

Construct a Data Frame Object

Usage

data.frame(..., row.names = NULL, check.rows = FALSE, check.names = TRUE,
    fix.empty.names = TRUE, stringsAsFactors = default.stringsAsFactors())

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

is.data.frame(x)

Arguments

... the objects to include 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. If the objects have different lengths for each of their elements, the value of the length must have a multiple relationship. Otherwise, an error is shown. This argument can be missing, in which case the function produces an empty data frame (0 columns by 0 rows).
row.names a (character) vector giving row names for the data frame. If this argument is a single string, and the data frame contains more than one row, this specifies the name of the input object containing the row names (rather than including that object into the data frame). If the vector is a single numeric value, it specifies the index of the input object containing the row names. Neither duplicated nor NA values are allowed in row.names. If this argument is NULL (the default), default row names are used.
check.rows a logical flag: if TRUE, and if several arguments imply row names, the function checks that these names are consistent. Usually, this flag is useful only in computations that claim to have selected the same rows from several parallel sources of data. This argument is ignored if row.names is supplied. The default is FALSE.
check.names a logical flag: if TRUE (the default), then variable names are changed to legal object names by substituting . for illegal characters such as blanks, parentheses, or commas. (See make.names for details.)
fix.empty.names a logical flag: if TRUE (the default), then unnamed arguments to data.frame will have names generated, based on deparsing the expression passes as the argument. If FALSE the data.frame will have unnamed columns corresponding to the unnamed arguments. Many other functions expect data.frames to contain only named columns, so you should attach names as soon as feasable.
stringsAsFactors a logical flag: if TRUE, then it converts character arguments to factors whose levels are the unique strings in the argument.

Note that as of version 5.2 of TIBCO Enterprise Runtime for R, default.stringsAsFactors() returns FALSE instead of the previous TRUE unless the user has execututed options(stringsAsFactors=TRUE) earlier in the session. This matches the same change in version 4.0.0 of open-source R.

x an object to be coerced to a data frame. This object can be anything representing one or more variables of a data frame. For example, it can be a vector representing a single column or a matrix representing multiple columns. The as.data.frame S3 method for the class of x is called to coerce x to a data frame If there is no S3 method for the class of x, the function exits with an error.
optional a logical value: if TRUE, keep the object default column names with no change. If FALSE (the default), try to construct the column names with a specified nm argument (if available) or the names of x (if available). Otherwise, construct the column names as a "X*", "V*", or "c*" format. (* can be 1, 2, 3, or combination of character elements). This argument is not available in the default and character class methods.

Details

A data.frame is a list whose elements are variables. The data frame always has an attribute "row.names" containing the row names, an attribute "names" containing names of the variables (which are normally unique), and the class "data.frame".
Value
data.frame returns a data frame consisting of all the variables supplied in the arguments. The variables are required to have the same number of observations. See Details for more information.
as.data.frame returns a data frame created from x. The S3 method method for the class of x does the coericion.
is.data.frame returns a logical value: TRUE if the object x is a data.frame and FALSE otherwise.
Examples
data.frame(c(1:4), c(4:5), list(c(1), c(2:3)), c(3))
# OK to create a dataframe. For the column c(1),c(2:3),c(3), 
# it will repeat to meet the length of c(1:4) and c(4:5)

as.data.frame(c(1, 2, 3)) # OK to create a dataframe with the column name is "c(1, 2, 3)"

is.data.frame((1:10)) # [1] FALSE

is.data.frame(data.frame(c(1, 2, 3))) # [1] TRUE

Package base version 6.0.0-69
Package Index