【发布时间】:2015-06-18 14:20:02
【问题描述】:
# first, create your data.frame
mydf <- data.frame(a = c(1,2,3), b = c(1,2,3), c = c(1,2,3))
# then, create your model.matrix
mym <- model.matrix(as.formula("~ a + b + c"), mydf)
# how can I normalize the model.matrix?
目前,我必须将我的 model.matrix 转换回 data.frame 才能运行我的规范化函数:
normalize <- function(x) { return ((x - min(x)) / (max(x) - min(x))) }
m.norm <- as.data.frame(lapply(m, normalize))
有没有办法通过简单地规范化 model.matrix 来避免这一步?
【问题讨论】:
-
m是什么?是mym还是一些转换后的数据集? -
@DavidArenburg m 是 mym 的真实代表。 m 来自我的实际代码,而 mym 是我为这个问题弥补的。
标签: r model.matrix