Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

as.data.frame: Coerce to a Data Frame

as.data.frameR Documentation

Coerce to a Data Frame

Description

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

Usage

as.data.frame(x, row.names = NULL, optional = FALSE, ...)## S3 method for class 'character'as.data.frame(x, ...,              stringsAsFactors = FALSE)## S3 method for class 'list'as.data.frame(x, row.names = NULL, optional = FALSE, ...,              cut.names = FALSE, col.names = names(x), fix.empty.names = TRUE,              check.names = !optional,              stringsAsFactors = FALSE)## S3 method for class 'matrix'as.data.frame(x, row.names = NULL, optional = FALSE,              make.names = TRUE, ...,              stringsAsFactors = FALSE)is.data.frame(x)

Arguments

x

anyR object.

row.names

NULL or a character vector giving the rownames for the data frame. Missing values are not allowed.

optional

logical. IfTRUE, setting row names andconverting column names (to syntactic names: seemake.names) is optional. Note that all ofR'sbase packageas.data.frame() methods useoptional only for column names treatment, basically with themeaning ofdata.frame(*, check.names = !optional).See also themake.names argument of thematrix method.

...

additional arguments to be passed to or from methods.

stringsAsFactors

logical: should the character vector be convertedto a factor?

cut.names

logical or integer; indicating if column names withmore than 256 (orcut.names if that is numeric) charactersshould be shortened (and the last 6 characters replaced by" ...").

col.names

(optional) character vector of column names.

fix.empty.names

logical indicating if empty column names, i.e.,"" should be fixed up (indata.frame) or not.

check.names

logical; passed to thedata.frame() call.

make.names

alogical, i.e., one ofFALSE, NA, TRUE,indicating what should happen if the row names (of the matrixx) are invalid. If they are invalid, the default,TRUE, callsmake.names(*, unique=TRUE);make.names=NA will use “automatic” row names and aFALSE value will signal an error for invalid row names.

Details

as.data.frame is a generic function with many methods, andusers and packages can supply further methods. For classes that actas vectors, often a copy ofas.data.frame.vector will workas the method.

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

Arrays can be converted to data frames. One-dimensional arrays aretreated like vectors and two-dimensional arrays like matrices. Arrayswith more than two dimensions are converted to matrices by‘flattening’ all dimensions after the first and creatingsuitable column labels.

Character variables are converted to factor columns unless protectedbyI.

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

Ifrow.names = NULL, row names are constructed from the namesor dimnames ofx, otherwise are the integer sequencestarting at one. Few of the methods check for duplicated row names.Names are removed from vector columns unlessI.

Value

as.data.frame returns a data frame, normally with all row names"" ifoptional = TRUE.

is.data.frame returnsTRUE if its argument is a dataframe (that is, has"data.frame" amongst its classes)andFALSE otherwise.

References

Chambers, J. M. (1992)Data for models.Chapter 3 ofStatistical Models in Seds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.

See Also

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


What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp