1

我想使用rowttestspackage:genefilter 中的函数。rowtests函数参数是:

>rowttests(x, fac)

x: Numeric matrix. The matrix must not contain ‘NA’ values.  For
      ‘rowttests’ and ‘colttests’, ‘x’ can also be an
      ‘ExpressionSet’.
fac: Factor which codes the grouping to be tested.

所以,我的输入是下面的数据框,我执行了以下步骤但得到了错误..

> dataframe
V1 V2 V3 V4
1  1  5  6  7
2  2  6  7  8
3  3  7  8  9
4  4  8  9 10
5  5  9 10 11
6  6 10 11 12
7  7 11 12 13

>mat <-as.matrix(dataframe)
> mat
 V1 V2 V3 V4
[1,]  1  5  6  7
[2,]  2  6  7  8
[3,]  3  7  8  9
[4,]  4  8  9 10
[5,]  5  9 10 11
[6,]  6 10 11 12
[7,]  7 11 12 13

>fac <- factor(c(1,1,2,2))

错误是:

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


> mode(mat)
[1] "numeric"

> class(mat)
[1] "matrix"

我也试过:

>mat1 <-matrix((stack(dataframe))[[1]],nrow=7, ncol=4)
>mat1
  [,1] [,2] [,3] [,4]
[1,]    1    5    6    7
[2,]    2    6    7    8
[3,]    3    7    8    9
[4,]    4    8    9   10
[5,]    5    9   10   11
[6,]    6   10   11   12
[7,]    7   11   12   13

同样的错误

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

谁能告诉我如何将数据框转换为矩阵,以便可以在 rowttests 函数中使用它?

4

0 回答 0