I'm having a problem with the function p.adjust
. I have a list containing 741 p-values and I want to use the p.adjust()
function to correct for multiple testing (FDR testing). This is what I have so far:
> x <- as.vector(pvalues1)
> p.adjust(x, method="fdr" n=length(x))
But I get the following error
Error in order (p, decreasing = TRUE) :
unimplemented type 'list' in 'orderVector1'
Can anyone help开发者_JS百科 me with this?
The problem you have is the your list containing the p-values is a vector already. What you wanted was a numeric vector. A list is just a general vector:
> l <- list(A = runif(1), B = runif(1))
> l
$A
[1] 0.7053136
$B
[1] 0.7053284
> as.vector(l)
$A
[1] 0.7053136
$B
[1] 0.7053284
> is.vector(l)
[1] TRUE
One option is to unlist()
the list, to produce a numeric vector:
> unlist(l)
A B
0.7053136 0.7053284
the benefit of that is that it preserves the names. An alternative is plain old as.numeric()
, which looses the names, but is otherwise the same as unlist()
:
> as.numeric(l)
[1] 0.7053136 0.7053284
For big vectors, you might not want to use the names in unlist()
, so an alternative that will speed that version up is:
> unlist(l, use.names = FALSE)
[1] 0.7053136 0.7053284
精彩评论