data.frame(..., row.names, check.rows=F, check.names=T, na.strings="NA", dup.row.names=F, stringsAsFactors=<<see below>>) data.frameAux(x, ...) as.data.frame(x, row.names=NULL, stringsAsFactors=<<see below>>, ...) is.data.frame(x)
data.frameAux()
;
see the note on methods below.
data.frameAux
the
...
argument plays a different role,
allowing optional
arguments to be passed to methods for these generic functions.
For
data.frameAux
the
...
argument can be a
bdFrame
.
dimnames
attribute
of a matrix argument, from the
row.names
argument of a previous data frame,
the
names
of a vector, or
the row numbers.
Supplying the argument explicitly as
NULL
forces the row numbers
to be used.
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.
This argument is ignored if
row.names
is supplied.
TRUE
, then variable names are made into legal S object
names by substituting
.
for illegal characters like blanks, parentheses, or commas
(see
for details).
na.strings
are considered to be missing values. The default
is "NA". character(0) means that no strings will be considered missing values.
TRUE
then duplicate row names are allowed.
The result may be much faster to create and subscript
(particularly for bootstrapping) if there are many rows.
TRUE
then convert character arguments
to factors whose levels are the unique strings in the argument. This may save time
and space if there a many repeated values in the strings and may make the statistical
modelling functions easier to use.
The default is
TRUE
, unless one sets
options(stringsAsFactors=FALSE)
.
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.
A
data.frame
is a list whose elements are variables. The data frame
will always have an attribute
"row.names"
containing the row names,
attribute
"names"
containing names of the variables, which are normally
unique, and class
"data.frame"
. It may also have an attribute
"dup.row.names"
, which, if non-null, indicates that row names need
not be unique.
In the case of
data.frameAux()
, the single argument will be
coerced to a list whose elements are variables with the same number
of observations. Columns of a matrix and elements of a list will normally
become individual variables.
Attributes
"names"
and
"row.names"
may be attached,
particular if they can be obtained naturally from
x
(e.g. from column and row names of a matrix, respectively);
data.frameAux
does not check these for uniqueness.
In the case of
as.data.frame()
, like
data.frameAux()
except that
the
"names"
and
"row.names"
must be present and unique,
and the value has class
"data.frame"
.
data.frame
calls
data.frameAux
for each of its data arguments.
data.frameAux
is a generic function, so that a method can be written
for a new class of objects to overrule the normal behavior described above.
as.data.frame
is also a generic function.
The default version of this function calls
data.frameAux
, then
attaches unique
row.names
and
names
attributes and
the
"data.frame"
class.
In
data.frame
,
row.names
could also be a numeric index or name indicating a
variable to use as row names rather than as a variable.
This behavior is deprecated due to ambiguity in some
cases, e.g. when objects contribute multiple columns.
data.frame(state.x77) data.frame(state.x77, row.names=state.abb) data.frame(state.x77, dup.row.names=T) # for faster bootstrap # The following are roughly equivalent except for speed data.frame(scan("myfile", what=list(a=0,b=0,c=""))) data.frame(scan("myfile", what=list(a=0,b=0,c="")), dup.row.names=T) as.data.frame(scan("myfile", what=list(a=0,b=0,c=""))) read.table("myfile")