[R] Exporting NMDS distance matris to csv
Gavin Simpson
gavin.simpson at ucl.ac.uk
Tue Jul 20 17:54:19 CEST 2010
On Tue, 2010-07-20 at 08:24 -0400, Graves, Gregory wrote:
> If you submit these lines, you end up with variable "vare.dis". I want
> to export vare.dis to csv. Stuck I am.
Hi Yoda ;-)
> library(vegan,logical.return = TRUE) #return=true verifies package is
> available
>
> library(MASS,logical.return=TRUE) #return=true verifies package is
> available
require(FOO)
is a shorter route to that for package 'FOO'
>
> data(varespec) #varespec is an example data file in the vegan package
>
> vare.dis <- vegdist(varespec)
>
> vare.dis #this is the triangular matrix I'd like to export
I don't know a way of exporting the triangular matrix directly, but if
you are happy with the full matrix, then that is simple.
?vegdist explains that it returns the same type of object as function
dist(). ?dist informs us of the as.matrix method for dist objects.
so:
write.csv(as.matrix(vare.dis), file = "vare_dis.csv")
should do what you want.
HTH
G
> x=format.data.frame(vare.dis) #nope, don't work
>
> x=format(vare.dis) #nope
>
> x=data.frame(vare.dis) #ditto
>
> x=unknown.function(vare.dis) #??? What is the unknown bit here to do
> this?
>
>
>
> #this is what I want to be able to do, i.e., write the matrix "x" out as
> a csv
>
> write.csv(x, file = "temp.csv")
>
>
>
> Gregory A. Graves, Lead Scientist
>
> Everglades REstoration COoordination and VERification (RECOVER)
>
> Restoration Sciences Department
>
> South Florida Water Management District
>
> Phones: DESK: 561 / 682 - 2429
>
> CELL: 561 / 719 - 8157
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Dr. Gavin Simpson [t] +44 (0)20 7679 0522
ECRC, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list