1

I am using the vegdist() function in the R package vegan to generate an association matrix for a species abundance dataset (the association matrix produced is 936 by 936). I want to be able to export/extract/coerce this association matrix into a dataframe or format writeable as a .csv so that I can use it for subsequent analyses. I know you can use the output from vegdist() for things like ordination after, or visualize using heat maps (coldiss()), but in this case I want to actually be able to see and manipulate the raw association matrix.

Any ideas? I wasn't sure that sample data would really help in this case since it is such a large dataset.

Mobiletainment
  • 20,096
  • 9
  • 75
  • 95
  • Hi and welcome to stackoverflow! Please read [about Stackoverflow](http://stackoverflow.com/about), [and show us what you have tried](http://stackoverflow.com/help/on-topic). If you own data set is to large to post, please have a look [here on how to make a minimal example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). Cheers. – Henrik Nov 18 '13 at 18:12

1 Answers1

3

Try:

write.csv(as.matrix(YOUR_MATRIX), "YOUR_MATRIX.csv")
Gavin Simpson
  • 164,190
  • 25
  • 377
  • 440
  • 2
    Indeed, +1. `vegdist()` returns an object of class `"dist"`, which is a vector with attributes. The `as.matrix.dist()` S3 method coerces this to a matrix. – Gavin Simpson Nov 19 '13 at 04:48
  • Thanks for your help! I was just about to post a data example, when I saw your answer and it was exactly what I needed. – user3005032 Nov 19 '13 at 14:16