julia
julia

Reputation: 23

Change from character to numeric without changing dimensions in R

I am calculating module preservation on R with WGCNA by following their tutorial, but I can't run the actual calculation, because it returns an error that it can only do it with numeric data. Sure enough, when I checked:

>is.numeric(datExprCTL)
[1] FALSE
>dim(datExprCTL)
[1] 185 2225

So I did the only thing I know to change it, but this is what happened:

>datExprCTL<-as.numeric(datExprCTL)    
>dim(datExprCTL)
NULL

And when I run my module preservation script, it does say: Error in colSums(!is.na(datExpr[useSamples, useGenes])) : 'x' must be an array of at least two dimensions

So, my question is how can I convert to numeric without losing the dimensions and going ahead with module preservation, which needs to have the correct dimensions.

Upvotes: 0

Views: 228

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226692

You want

storage.mode(datExprCTL) <- "numeric"

Upvotes: 2

Related Questions