2013-02-27 136 views
0

我有一個數據框有4列和679行,我需要使用genefilter包中的da函數rowttest執行ttest。想要列出兩個第一列和另外兩列。如何在R中執行rowttest?

A_R1 A_R2 B_R1 B_R2 
1  2  7  7 
4  5  8  7.5 
5  5  9  NA 
6  5  10  NA 
... 

我使用了這段代碼,但我並不確定「fac」是什麼意思。我認爲這是行數。

#t.test is the dataframe used 
ttest2=na.omit(ttest) 
rowttests(as.matrix(ttest2),fac=679,tstatOnly = FALSE) 

我有這樣的錯誤:

Error in function (classes, fdef, mtable) : 
    unable to find an inherited method for function ‘rowttests’ for signature ‘"matrix", "numeric"’ 

Error in rowcoltt(x, factor(integer(ncol(x))), tstatOnly, 1L) : 
    Invalid argument 'x': must be a real matrix. 

有人能幫助我嗎?

回答

0

看到了嗎? rowtests

rowttests(x, fac, tstatOnly = FALSE) x Numeric matrix and fac Factor which codes the grouping to be tested

在這裏你給一個矩陣和數字,你必須強迫德數值的因素。所以改變

rowttests(as.matrix(ttest2),fac=679,tstatOnly = FALSE) 

rowttests(as.matrix(ttest2),fac=factor(679),tstatOnly = FALSE) 
+0

謝謝,但存在的問題之一是這個錯誤: 錯誤rowcoltt(X,FAC,tstatOnly,1L): 無效參數 'X':必須是一個真正的矩陣。 我轉換矩陣中的data.frame。我不明白 – 2013-02-27 09:54:01

+0

是的,但我無法幫助,因爲我沒有在您的問題中看到x的定義。 – agstudy 2013-02-27 09:58:42

+0

x是上面顯示的表 – 2013-02-27 10:01:58

2

的第二個參數是指可以是表示在其上執行的t-檢驗的組(列)的一個因素。

> m=matrix(runif(80), 20) 
> rowttests(m, factor(c("M", "M", "F", "F"))) 
     statistic   dm  p.value 
1 1.15567467 0.297622456 0.367224496 
2 0.81334422 0.328723537 0.501449912 
.... 
1

該數據不能是一個整數矩陣!

#x是這裏整數data.frame ...

x <- read.table("HFLF.txt", header=TRUE, row.names=1) 
g <- c("HF","HF","LF","LF") 
results<- rowttests(x, factor(g)) 

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘rowttests’ for signature ‘"data.frame", "factor"’

#試圖從數據幀將X的矩陣...

x <- as.matrix(read.table("HFLF.txt", header=TRUE, row.names=1)) 
g <- c("HF","HF","LF","LF") 
results<- rowttests(x, factor(g)) 

Error in rowcoltt(x, fac, tstatOnly, 1L) : Invalid argument 'x': must be a real matrix.

#x是實數數據框這裏(帶小數位)...

x <- read.table("HFLF.txt", header=TRUE, row.names=1) 
g <- c("HF","HF","LF","LF") 
results<- rowttests(x, factor(g)) 

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘rowttests’ for signature ‘"data.frame", "factor"’

#試圖從數據幀將X的矩陣...

results<- rowttests(as.matrix(x), factor(g)) 
head(results) 

我想通了,從一些 「Joran」 張貼在這裏: http://w3facility.org/question/conversion-of-data-frame-to-matrix-error/

+0

我的意思是答案本身並不能真正幫助這個特定的問題,但錯誤信息有助於谷歌它,並使它非常有助於確定我自己的錯誤。那謝謝啦! – 2015-09-16 18:41:21