[R] double matrix?

Don McKenzie dmck at u.washington.edu
Wed Jul 31 23:46:13 CEST 2013


What are the entries in your matrix?  If they are something that won't coerce to numeric, you need to backtrack. Note how R distinguishes types of characters.

> as.numeric("a")
[1] NA
Warning message:
NAs introduced by coercion 
> as.character(2)
[1] "2"
> as.numeric("2")
[1] 2


On Jul 31, 2013, at 1:47 PM, bruce087 at umn.edu wrote:

> Hi-
> 
> I have a 37 X 473971 character matrix that I am trying to convert into a numeric matrix. When I use the code:
> 
> class(matrix) = "numeric"  
> I end up with something called a "double matrix" whose dimensions are still 37 X 473971
> 
> I have also tried 
> new = apply(matrix,2, as.numeric) and got the same thing.
> 
> The analysis code I am ultimately attempting to run on this data requires that it be in a numerical matrix, and it is really not okay with a double matrix.
> 
> Does anyone know how to fix this?
> 
> Thanks.
> 
> -- 
> Jessica R.B. Musselman, MS
> T32 Trainee/Doctoral Candidate
> University of Minnesota
> Department of Pediatrics
> Division of Epidemiology/Clinical Research
> Mayo Mail Code 715
> Room 1-195 Moos Tower
> 420 Delaware St. SE
> Minneapolis MN 55455
> Phone: (612)626-3281
> email: bruce087 at umn.edu
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Professor
School of Forest Resources, College of the Environment
CSES Climate Impacts Group
University of Washington

phone: 206-732-7824
dmck at uw.edu



More information about the R-help mailing list