[R-sig-eco] [EXTERNAL] Re: trasformation of matrix for iNEXT extrapolation interpolation of Hill's numbers

Philippi, Tom tom_ph|||pp| @end|ng |rom np@@gov
Thu Jun 20 22:00:47 CEST 2019


Or, if the component matrices need to be numeric with species names as row
names and sites as column names, Dave Roberts' labdsv package has matrify()
that does that and fills in the unseen combinations with 0s as opposed to
NAs.  Converting {site, taxon, abundance} triplets to matrix form is a very
common operation for vegan, labdsv, and other vegetation packages.  Thus,
you could build the list of 4 matrices with something like:

ciliates <- list(
                     M1 = labdsv::matrify(d1),
                     M2 = labdsv::matrify(d2),
                     M3 = labdsv::matrify(d3),
                     M4 = labdsv::matrify(d4)
                    )

Tom



On Thu, Jun 20, 2019 at 11:35 AM Law, Jason <Jason.Law using portlandoregon.gov>
wrote:

> I'm not sure what your data looks like. But the reshape package can be
> used to easily create matrix or array data from a 'long' format. Combining
> that with split would make it relatively to create matrices.
>
> library(iNEXT)
> library(reshape2)
> data(ciliates)
> # Maybe your data is in long format like this:
> df <- melt(ciliates, varnames = c('species', 'sample'), value.name =
> 'count')
> # Then this will work
> df.list <- lapply(split(df, df$L1), function(x) acast(x, species ~ sample,
> value.var='count'))
>
> # If your data is just one wide (sorted) matrix, then you just need lapply
> and the column indices
> mat <- acast(df, species ~ L1 + sample, value.var='count')
> df.list <- lapply(list(c(1,17), c(18,36), c(37,51)), function(i)
> mat[,i[1]:i[2]])
>
> Regards,
>
> Jason
>
> -----Original Message-----
> From: R-sig-ecology <r-sig-ecology-bounces using r-project.org> On Behalf Of
> Irene Adamo
> Sent: Thursday, June 20, 2019 07:28
> To: r-sig-ecology using r-project.org
> Subject: [R-sig-eco] trasformation of matrix for iNEXT extrapolation
> interpolation of Hill's numbers
>
> Hi all,
>
> I am working with iNEXT package for diversity analyses however, I would
> like to use a incidence_raw data type which in iNEXT is a list of matrices
> like this:
>
> data(ciliates)
> head(ciliates)
>
> $SouthernNamibDesert
>                                                      x9 x17 x19 x20 x21 x22
> x23 x24
> Acaryophrya.collaris                                  0   0   0   0   0   0
>   0   0
> Actinobolina.multinucleata.n..sp.                     0   0   0   0   0   0
>   0   0
> Afroamphisiella.multinucleata.n..sp.                  0   0   0   0   0   0
>   0   0
> Afrothrix.multinucleata.n..sp.                        0   1   0   0   0   0
>   0   0
> Amphisiella.binucleata.multicirrata.n..ssp.           0   0   0   0   0   0
>   0   0
> Amphisiella.elegans.n..sp.                            0   0   0   0   0   0
>   1   0
> Amphisiella.longiseries.n..sp.                        0   0   0   0   0   0
>   0   0
> Amphisiella.magnigranulosa                            0   0   0   0   0   0
>   0   1
> Amphisiella.multinucleata.n..sp.                      0   0   0   0   0   0
>   0   0
> Amphisiella.namibiensis.n..sp.                        0   0   0   0   0   0
>   0   0
> Amphisiella.polycirrata                               0   0   0   0   0   0
>   0   0
> Amphisiella.procera.n..sp.                            1   0   0   0   0   0
>   0   0
>
> do you know how can I create anlist with four matrices like the one they
> have in example data?
>
> thanks a lot for any help!
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>

	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list