data.matrix;
时间: 2023-11-17 21:06:16 浏览: 108
DataMatrix 二维码生成 和解码 C#程序
The data.matrix() function in R is used to convert a data frame or other object into a matrix. It creates a matrix where each column represents a variable and each row represents an observation. The resulting matrix will have the same number of rows and columns as the original data frame.
Usage:
data.matrix(x)
Arguments:
x: A data frame or other object to be converted into a matrix.
Example:
# Create a data frame
df <- data.frame(x = c(1, 2, 3), y = c(4, 5, 6))
# Convert data frame to matrix
mat <- data.matrix(df)
# Print matrix
mat
Output:
x y
[1,] 1 4
[2,] 2 5
[3,] 3 6
阅读全文