[R-sig-eco] trasformation of matrix for iNEXT extrapolation interpolation of Hill's numbers
Law, Jason
J@@on@L@w @end|ng |rom port|@ndoregon@gov
Thu Jun 20 20:34:03 CEST 2019
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
More information about the R-sig-ecology
mailing list