Hello everyone!

I'm having a problem in casting a data frame with the reshape package. I
have an original data set of species abundances in replicate samples at
certain sites, with the following form:

 

SITE   SPECIES   Replicate1   Replicate2   Replicate3

   I               A              1                   3                 0

   I               B              2                   5                1

   I               C              1                   0                 2

   II             A              4                   2                0

   II             C              1                   0                0

   II             D              6                   3                3

 

Please notice that site II does not have species B and has a new species D,
the remaining two are shared with site I.

 

I need to get these data in the form of a matrix like:

 

SITE.REPLICATE     A          B         C         D

            I.1                   1          2          1          NA

            I.2                   3          5          0          NA

            I.3                   0          1          2          NA

            II.1                  4          NA      1          6

            II.2                  2          NA      0          3

            II.3                  0          NA      0          3

 

Using the above "toy data" in R, everything works fine using melt and recast
as follows (lets call test to may initial matrix):

> testm <- melt (test, id.var=c("SITE","SPECIES"))

> testc <- cast(testm, ...~SPECIES)

> testc

   SITE   variable    A  B C  D

1    I    Replicate1  1  2 1 NA

2    I    Replicate2  3  5 0 NA

3    I    Replicate3  0  1 2 NA

4   II    Replicate1  4 NA 1  6

5   II    Replicate2  2 NA 0  3

6   II    Replicate3  0 NA 0  3

 

 However, when I use the same code in my real data set which is considerably
larger (73 sites and 7 replicates for site, resulting in a molten matrix of
14469 x 4), the cast function does some kind of aggregation (in fact it
advices of an aggregation using the default fun.aggregate) that I was not
able to understand. I also tried to split my original data frame in order to
get molten matrices smaller than 5500x4, but I got the same problem.

Could anyone help me with this?

 

 (I use R 2.8.1 for Windows)

 

Thank you very very much in advance!

 

 

Cheers,

 

Dulce

 

  

 


	[[alternative HTML version deleted]]

