[R] List creation based on matrix

PIKAL Petr petr.pikal at precheza.cz
Mon Sep 24 15:12:22 CEST 2012


Hi

Your attachment came scrambled. Something wrong with dput?

anyway

having
> mat<-matrix(1:6, 3,2)
> df<-as.data.frame(mat)
>df$species<-letters[1:3]
> df
  V1 V2 species
a  1  4       a
b  2  5       b
c  3  6       c

> library(reshape)

> melt(df, id="species")
  species variable value
1       a       V1     1
2       b       V1     2
3       c       V1     3
4       a       V2     4
5       b       V2     5
6       c       V2     6


Gives probably what you want

Petr

> -----Original Message-----
> From: Benjamin Gillespie [mailto:gybrg at leeds.ac.uk]
> Sent: Monday, September 24, 2012 2:53 PM
> To: PIKAL Petr; r-help at r-project.org
> Subject: RE: [R] List creation based on matrix
> 
> Please see the attached .csv files for further info,
> 
> Thanks guys,
> 
> Ben Gillespie
> Research Postgraduate
> 
> School of Geography
> University of Leeds
> Leeds
> LS2 9JT
> 
> Tel: +44(0)113 34 33345
> Mob: +44(0)770 868 7641
> http://www.geog.leeds.ac.uk/
> ________________________________________
> From: PIKAL Petr [petr.pikal at precheza.cz]
> Sent: 24 September 2012 13:39
> To: Benjamin Gillespie; r-help at r-project.org
> Subject: RE: [R] List creation based on matrix
> 
> Hi
> 
> > -----Original Message-----
> > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> > project.org] On Behalf Of benrgillespie
> > Sent: Monday, September 24, 2012 1:20 PM
> > To: r-help at r-project.org
> > Subject: [R] List creation based on matrix
> >
> > Hi guys,
> >
> > It would be great if you could help me with this one...
> >
> > I'm looking to create a script to convert a matrix of species
> > abundance
> > e.g:
> >
> > <http://r.789695.n4.nabble.com/file/n4643978/species_matrix.jpg>
> >
> > into two vectors e.g:
> >
> > <http://r.789695.n4.nabble.com/file/n4643978/communitylist.jpg>
> >
> > ----------------
> >
> > If you feel there is no easy answer to this and that it would be
> > easier to do in excel or open office calc (or another program),
> please
> > let me
> 
> Not much can be done easier in Excel. If you do not fail to provide
> data you could get better answers.
> 
> Regards
> Petr
> 
> > know.
> >
> > Thanks in advance for your help and let me know if you require any
> > further information,
> >
> > Ben Gillespie (Research Postgrad)
> >
> >
> >
> >
> >
> > --
> > View this message in context: http://r.789695.n4.nabble.com/List-
> > creation-based-on-matrix-tp4643978.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > 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.




More information about the R-help mailing list