我有一個數據框,我想用它來生成設計矩陣。model.matrix刪除列
>ct<-read.delim(filename, skip=0, as.is=TRUE, sep="\t", row.names = 1)
> ct
s2 s6 S10 S14 S3 S7 S11 S15 S4 S8 S12 S16
group 1 1 1 1 2 2 2 2 3 3 3 3
donor 1 2 3 4 1 2 3 4 1 2 3 4
>factotum<-apply(ct,1,as.factor) # to turn rows into factors.
>design <- model.matrix(~0 + factotum[,1] + factotum[,2])
最終,我將生成一個字符串並使用as.formula()而不是對公式進行硬編碼。無論如何,這工作併產生一個設計矩陣。儘管如此,它留下了一列。
>design
factotum[, 1]1 factotum[, 1]2 factotum[, 1]3 factotum[, 2]2 factotum[, 2]3 factotum[, 2]4
1 1 0 0 0 0 0
2 1 0 0 1 0 0
3 1 0 0 0 1 0
4 1 0 0 0 0 1
5 0 1 0 0 0 0
6 0 1 0 1 0 0
7 0 1 0 0 1 0
8 0 1 0 0 0 1
9 0 0 1 0 0 0
10 0 0 1 1 0 0
11 0 0 1 0 1 0
12 0 0 1 0 0 1
通過我的推理,列名稱應該是: factotum的[1] 1個factotum的[1] 2 factotum的[1] 3,factotum的[2] 1,factotum的[2] 2 factotum [,2] 3 factotum [,2] 4。這些將被重新命名爲group1,group2,group3,donor1,donor2,donor3,donor4。
這意味着factotum [,2] 1或donor1缺失。我在做什麼,這會失蹤?任何幫助將不勝感激。
乾杯 本。