[R] matrix to list
Henrique Dallazuanna
wwwhsd at gmail.com
Thu Sep 18 13:18:29 CEST 2008
Try this:
m <- matrix(rep(1:3, 3), 3, dimnames = list(letters[1:3], letters[1:3]))
as.data.frame.table(t(m))
On Wed, Sep 17, 2008 at 10:52 PM, Pinder, Adrian
<Adrian.Pinder at dec.wa.gov.au> wrote:
> Hi, can someone please tell me how to convert a square matrix to a list in R?
>
> i.e. I want to convert from:
>
> a b c
> a 1 1 1
> b 2 2 2
> c 3 3 3
>
> to:
>
> a a 1
> a b 1
> a c 1
> b a 2
> b b 2
> b c 2
> c a 3
> c b 3
> c c 3
>
>
> Thanks,
> Adrian.
>
>
> Adrian Pinder
> Senior Research Scientist
> Wetland Research
> Dept. Environment and Conservation
> P.O. Box 51 Wanneroo 6946
> Western Australia
> adrian.pinder at dec.wa.gov.au (W)
> apnlp1 at optusnet.com.au (H)
> http://www.naturebase.net/content/view/2475/1338/
> ph (61) 08 94055153, fax (61) 08 93061641
> mob. 0438 935 932
>
>
>
> This email, together with any attachments, is intended for the
> addressee only. It may contain confidential or privileged information.
> If you are not the intended recipient of this email, please notify
> the sender, delete the email and attachments from your system and
> destroy any copies you may have taken of the email and its attachments.
> Duplication or further distribution by hardcopy, by electronic means
> or verbally is not permitted without permission.
>
> ______________________________________________
> 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list