[R] Formating a matrix in a exotic way
Suppose I have following arbitrary matrix: set.seed(1) mat - matrix(rnorm(6), 3, 2) mat [,1] [,2] [1,] -0.6264538 1.5952808 [2,] 0.1836433 0.3295078 [3,] -0.8356286 -0.8204684 Now I want to make a simple object like (character type): -0.6264538,1.5952808;0.1836433,0.3295078;-0.8356286,-0.8204684 I would be really grateful if somebody guide me how to perform that. Thanks for your time. __ R-help@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.
Re: [R] Formating a matrix in a exotic way
On Sun, Sep 19, 2010 at 3:41 PM, Megh Dal megh700...@yahoo.com wrote: Suppose I have following arbitrary matrix: set.seed(1) mat - matrix(rnorm(6), 3, 2) mat [,1] [,2] [1,] -0.6264538 1.5952808 [2,] 0.1836433 0.3295078 [3,] -0.8356286 -0.8204684 Now I want to make a simple object like (character type): -0.6264538,1.5952808;0.1836433,0.3295078;-0.8356286,-0.8204684 I would be really grateful if somebody guide me how to perform that. Try this: toString(t(mat)) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@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.
Re: [R] Formating a matrix in a exotic way
On Sun, Sep 19, 2010 at 4:23 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Sun, Sep 19, 2010 at 3:41 PM, Megh Dal megh700...@yahoo.com wrote: Suppose I have following arbitrary matrix: set.seed(1) mat - matrix(rnorm(6), 3, 2) mat [,1] [,2] [1,] -0.6264538 1.5952808 [2,] 0.1836433 0.3295078 [3,] -0.8356286 -0.8204684 Now I want to make a simple object like (character type): -0.6264538,1.5952808;0.1836433,0.3295078;-0.8356286,-0.8204684 I would be really grateful if somebody guide me how to perform that. Try this: toString(t(mat)) Didn't notice the semicolons the first time. Here is a revision: paste(apply(mat, 1, toString), collapse = ;) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@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.
Re: [R] Formating a matrix in a exotic way
On Sep 19, 2010, at 3:41 PM, Megh Dal wrote: Suppose I have following arbitrary matrix: set.seed(1) mat - matrix(rnorm(6), 3, 2) mat [,1] [,2] [1,] -0.6264538 1.5952808 [2,] 0.1836433 0.3295078 [3,] -0.8356286 -0.8204684 Now I want to make a simple object like (character type): -0.6264538,1.5952808;0.1836433,0.3295078;-0.8356286,-0.8204684 paste( apply(mat,1,paste, collapse=,), collapse=;) [1] -0.626453810742332,1.59528080213779;0.183643324222082,0.329507771815361 ;-0.835628612410047,-0.820468384118015 I would be really grateful if somebody guide me how to perform that. Thanks for your time. __ R-help@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.