[R] List creation based on matrix

Benjamin Gillespie gybrg at leeds.ac.uk
Mon Sep 24 15:51:53 CEST 2012


Hi Arun,

I've just run through that - thanks so much, it worked perfectly. Learnt lots of new commands too :)

Thanks for all your help - awesome!

ps. the only thing I changed was to remove the '0' from the first line after 'paste'.

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: arun [smartpink111 at yahoo.com]
Sent: 24 September 2012 14:01
To: Benjamin Gillespie
Cc: PIKAL Petr; R help
Subject: Re: [R] List creation based on matrix

Hi,

Couldn't find your attachment.
But, from Nabble, I saw the data.
Try this:dat1<-data.frame(Species=paste0("Species",1:6),Site1=c(5,NA,4,NA,3,NA),Site2=c(4,NA,4,4,NA,4),Site3=c(NA,5,NA,NA,NA,NA),Site4=c(NA,NA,NA,6,5,NA))
dat2<-melt(dat1)
dat3<-dat2[!is.na(dat2$value),]
dat3<-dat3[,1:2]
colnames(dat3)[2]<-"Site"
dat3$Species<-gsub(".*(\\d)","\\1",dat3$Species)
 dat3$Site<-gsub(".*(\\d)","\\1",dat3$Site)
 dat4<-dat3[,c(2,1)]
 dat4
 rownames(dat4)<-1:nrow(dat4)
 dat4
#   Site Species
#1     1       1
#2     1       3
#3     1       5
#4     2       1
#5     2       3
#6     2       4
#7     2       6
#8     3       2
#9     4       4
#10    4       5
A.K.



----- Original Message -----
From: Benjamin Gillespie <gybrg at leeds.ac.uk>
To: PIKAL Petr <petr.pikal at precheza.cz>; "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Monday, September 24, 2012 8:52 AM
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.

______________________________________________
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