Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

data.matrix: Convert a Data Frame to a Numeric Matrix

data.matrixR Documentation

Convert a Data Frame to a Numeric Matrix

Description

Return the matrix obtained by converting all the variables in a dataframe to numeric mode and then binding them together as the columns ofa matrix. Factors and ordered factors are replaced by their internalcodes.

Usage

data.matrix(frame, rownames.force = NA)

Arguments

frame

a data frame whose components are logical vectors,factors or numeric or character vectors.

rownames.force

logical indicating if the resulting matrixshould have character (rather thanNULL)rownames. The default,NA, usesNULLrownames if the data frame has ‘automatic’ row.names or for azero-row data frame.

Details

Logical and factor columns are converted to integers. Charactercolumns are first converted to factors and then to integers. Any othercolumn which is not numeric (according tois.numeric) isconverted byas.numeric or, for S4 objects,as(, "numeric"). If all columns are integer (afterconversion) the result is an integer matrix, otherwise a numeric(double) matrix.

Value

Ifframe inherits from class"data.frame", an integer ornumeric matrix of the same dimensions asframe, with dimnamestaken from therow.names (orNULL, depending onrownames.force) andnames.

Otherwise, the result ofas.matrix.

Note

The default behaviour for data frames differs fromR < 2.5.0 whichalways gave the result character rownames.

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

as.matrix,data.frame,matrix.

Examples

DF <- data.frame(a = 1:3, b = letters[10:12],                 c = seq(as.Date("2004-01-01"), by = "week", length.out = 3),                 stringsAsFactors = TRUE)data.matrix(DF[1:2])data.matrix(DF)

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