ta.frame ` are converted to factor
columns unless protected by ` [ I ](/link/I?package=base&version=3.6.2) ` or
argument ` stringsAsFactors ` is false. If a list or data frame or matrix is
passed to ` data.frame ` it is as if each component or column had been passed
as a separate argument (except for matrices protected by ` [ I
](/link/I?package=base&version=3.6.2) ` ).

Objects passed to ` data.frame ` should have the same number of rows, but
atomic vectors (see ` [ is.vector
](/link/is.vector?package=base&version=3.6.2) ` ), factors and character
vectors protected by ` [ I ](/link/I?package=base&version=3.6.2) ` will be
recycled a whole number of times if necessary (including as elements of list
arguments).

If row names are not supplied in the call to ` data.frame ` , the row names
are taken from the first component that has suitable names, for example a
named vector or a matrix with rownames or a data frame. (If that component is
subsequently recycled, the names are discarded with a warning.) If ` row.names
` was supplied as ` NULL ` or no suitable component was found the row names
are the integer sequence starting at one (and such row names are considered to
be ‘automatic’, and not preserved by ` [ as.matrix
](/link/as.matrix?package=base&version=3.6.2) ` ).

If row names are supplied of length one and the data frame has a single row,
the ` row.names ` is taken to specify the row names and not a column (by name
or number).

Names are removed from vector inputs not protected by ` [ I
](/link/I?package=base&version=3.6.2) ` .

` default.stringsAsFactors ` is a utility that takes ` [ getOption
](/link/getOption?package=base&version=3.6.2) ("stringsAsFactors") ` and
ensures the result is ` TRUE ` or ` FALSE ` (or throws an error if the value
is not ` NULL ` ).

##  References

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.

##  See Also

` [ I ](/link/I?package=base&version=3.6.2) ` , ` [ plot.data.frame
](/link/plot.data.frame?package=base&version=3.6.2) ` , ` [ print.data.frame
](/link/print.data.frame?package=base&version=3.6.2) ` , ` [ row.names
](/link/row.names?package=base&version=3.6.2) ` , ` [ names
](/link/names?package=base&version=3.6.2) ` (for the column names), ` [
[.data.frame ](/link/%5B.data.frame?package=base&version=3.6.2) ` for
subsetting methods  and ` I(matrix(..)) ` examples; ` [ Math.data.frame
](/link/Math.data.frame?package=base&version=3.6.2) ` etc, about _Group_
methods for ` data.frame ` s; ` [ read.table
](/link/read.table?package=base&version=3.6.2) ` , ` [ make.names
](/link/make.names?package=base&version=3.6.2) ` .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fdata.frame&utm_source=r-docs&utm_medium=docs&utm_term=data.frame&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    L3 <- LETTERS[1:3]
    fac <- sample(L3, 10, replace = TRUE)
    (d <- data.frame(x = 1, y = 1:10, fac = fac))
    ## The "same" with automatic column names:
    data.frame(1, 1:10, sample(L3, 10, replace = TRUE))
    
    is.data.frame(d)
    
    ## do not convert to factor, using I() :
    (dd <- cbind(d, char = I(letters[1:10])))
    rbind(class = sapply(dd, class), mode = sapply(dd, mode))
    
    stopifnot(1:10 == row.names(d))  # {coercion}
    
    (d0  <- d[, FALSE])   # data frame with 0 columns and 10 rows
    (d.0 <- d[FALSE, ])   # <0 rows> data frame  (3 named cols)
    (d00 <- d0[FALSE, ])  # data frame with 0 columns and 0 rows
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fdata.frame&utm_source=r-docs&utm_medium=docs&utm_term=data.frame&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)