[R] split character string in matrix into character vector and numeric vector

From: Kim Milferstedt <milferst_at_uiuc.edu>
Date: Wed, 21 May 2008 12:11:12 -0500


I've got a matrix consisting of one column with n rows. Each field in the matrix is filled with a character vector.

I would like to convert this matrix into a character vector containing the B03_MAH-type entries from the beginning of each row and a data.frame that contains the numeric data, but I am stuck.

I have tried to use textConnection with sep = " " but since there is sometimes more than two spaces separating the entries, I obtain a result with columns full of NAs.

Then I tried sub() to replace the all multi-spaces to get only one space that separates each entry but that didn't work either.

Do you know a good way to convert this matrix?

Thanks already,


taxa.vec "B03_MAH     0.2115  0.2087  0.2087  0.2147  0.2115  0.2176" 
taxa.vec "F02_SSBH    0.2162  0.2191  0.2133  0.2130  0.2220  0.2158" 
taxa.vec "G04_MAH     0.2083  0.2111  0.2055  0.2115  0.2140  0.2087" 
taxa.vec "A04_MAH     0.2097  0.2126  0.2069  0.2065  0.2097  0.2037" 
taxa.vec "E03_MAH     0.2097  0.2069  0.2069  0.2130  0.2155  0.2101"

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. Received on Wed 21 May 2008 - 17:53:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 21 May 2008 - 18:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive