Questions tagged «indicator»


10
R模型矩阵中因子的所有层次
我有一个data.frame由数字和因子组成的变量,如下所示。 testFrame <- data.frame(First=sample(1:10, 20, replace=T), Second=sample(1:20, 20, replace=T), Third=sample(1:10, 20, replace=T), Fourth=rep(c("Alice","Bob","Charlie","David"), 5), Fifth=rep(c("Edward","Frank","Georgia","Hank","Isaac"),4)) 我想建立一个matrix将虚拟变量分配给因子并仅保留数字变量的方法。 model.matrix(~ First + Second + Third + Fourth + Fifth, data=testFrame) 如预期的那样,在运行时,lm这会将每个因子的一个水平作为参考水平。但是,我想为matrix所有因素的每个层次建立一个带有虚拟/指标变量的。我正在为此建立矩阵,glmnet所以我不必担心多重共线性。 有没有一种方法可以model.matrix为每个因子水平创建虚拟对象?
69 r  matrix  model  indicator 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.