Skip to content
Prev 137220 / 398498 Next

Specaccum

On Wed, 2008-02-20 at 13:24 +0100, Alfonso P?rez Rodr?guez wrote:
That is just the _printed_ representation of the resulting object. In R,
don't believe your eyes - what is printed is not always an accurate
reflection of the complete object!
I'll start with a reproducible example, from ?specaccum

require("vegan")
data(BCI)
sp1 <- specaccum(BCI)
str(sp1)

The latter call yields:

List of 6
 $ call    : language specaccum(comm = BCI)
 $ method  : chr "exact"
 $ sites   : int [1:50] 1 2 3 4 5 6 7 8 9 10 ...
 $ richness: num [1:50]  90.8 121.6 139.0 150.7 159.2 ...
 $ sd      : num [1:50] 6.93 7.19 7.00 6.64 6.25 ...
 $ perm    : NULL
 - attr(*, "class")= chr "specaccum"

Note the class - "specaccum" - and R has no idea how to convert this to
a data frame or matrix - there is no as.data.frame.specaccum() and this
is because how do you combine 3 vectors of length 50 into a data frame
with other information that is of a different type and length? You
can't.

So, now your problem boils down to extracting the relevant information
from sp1 and writing that out as a data frame. This is very easy. Given
your email I presume you are interested in the 'sites', 'richness' and
'sd' components:

my.res <- with(sp1, data.frame(sites, richness, sd))
head(my.res)

The latter call yielding the first 6 lines of my.res (there are 50 in
total):

  sites richness       sd
1     1  90.7800 6.934811
2     2 121.6098 7.193362
3     3 139.0459 7.001993
4     4 150.7116 6.635769
5     5 159.2363 6.248117
6     6 165.8306 5.894738

Now just write out my.res using write.table()

write.table(my.res, file = "my.results.txt")

Which works for me.

Is that what you wanted?

HTH

G