[R] character vector -> numeric matrix ??
Steve Lianoglou
mailinglist.honeypot at gmail.com
Tue Jul 28 19:20:47 CEST 2009
Hi,
On Jul 28, 2009, at 1:13 PM, kathie wrote:
>
> Dear R users...
>
> I'd like to change this character vector, "zz",
>
> zz <- c("12","56","89")
>
> to the following numeric matrix.
>
> [,1] [,2]
> [1,] 1 2
> [2,] 5 6
> [3,] 8 9
>
>
> Actually, "zz" vector has a long length.
>
> Any comments will be greatly appreciated.
>
> Kathryn Lord
pieces <- strsplit(zz, "") # look at what pieces looks like
my.data <- as.numeric(unlist(pieces))
my.matrix <- t(matrix(my.data, nrow=2))
my.matrix
[,1] [,2]
[1,] 1 2
[2,] 5 6
[3,] 8 9
-steve
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the R-help
mailing list