从data.frame到矩阵

时间:2018-10-18 16:14:15

标签: r dataframe

我对R知道;我有8个变量(列)和587632个观察值(行)的数据结构。

AggregateActivities <- data.frame(sleep, eating, personalcare, cooking, houseclean, laundry, ironing, travel)

我想将AggregateActivities数据帧转换为矩阵,例如

dat <- matrix(c( values from AggregateActivities)  nrow=587632, ncol=8, byrow=TRUE)

有人可以帮我这个忙吗

2 个答案:

答案 0 :(得分:0)

只需更改此:

AggregateActivities <- data.frame(sleep, eating, personalcare)

为此:

AggregateActivities <- matrix(data.frame(sleep, eating, personalcare))

答案 1 :(得分:0)

data.matrix函数是专门为此目的而构建的>

AggMat <- data.matrix( AggregateActivities )