Subsetting and Ordering of Related Data Tables
mefaTables.RdThis function is called by the mefa function to subset the community data matrix and the related data frames, but can be applied more generally for subsetting and ordering.
Arguments
- xtab
a data matrix.
- dframe
a data frame.
- margin
margin of the
xtabmatrix to use row (margin = 1) or column (margin = 2) names in comparison with the rownames ofdframe.- index
if
NULLrownames are used directly, else it can be used to set which column ofdframeshould be used as rowname and for comparison.- drop.index
logical, should the
indexcolumn ofdframebe deleted (ifindex != NULL).- xtab.fixed
logical, if
TRUEthextabmatrix is left intact, anddframeis subsetted accordingly. IfFALSE, bothxtabanddframeare subsetted, and returned values are based on the the intersect of the compared names.
Value
Returns a list with elements xtab (matrix) and dtab (data frame), corresponding to the subsetted xtab and dframe data sets, respectively. Original column and row orderings in the input matrix xtab are preserved.
References
S\'olymos P. (2008) mefa: an R package for handling and reporting count data. Community Ecology 9, 125–127.
S\'olymos P. (2009) Processing ecological data in R with the mefa package. Journal of Statistical Software 29(8), 1–28. doi:10.18637/jss.v029.i08
Author
P\'eter S\'olymos, solymos@ualberta.ca
Examples
x <- matrix(rpois(20,1), 5, 4)
## Note the reverse alphabetical names
rownames(x) <- letters[5:1]
x
#> [,1] [,2] [,3] [,4]
#> e 1 1 1 0
#> d 0 1 3 5
#> c 1 1 1 0
#> b 1 0 0 1
#> a 2 0 1 2
f <- data.frame(matrix(rnorm(30), 10, 3))
rownames(f) <- letters[1:10]
f
#> X1 X2 X3
#> a 0.57770907 2.6825572 0.1316706
#> b 0.11819487 -0.3612213 0.4886288
#> c -1.91172049 0.2133557 -1.6994506
#> d 0.86208648 1.0743459 -1.4707363
#> e -0.24323674 -0.6650882 0.2841503
#> f -0.20608719 1.1139524 1.3373204
#> g 0.01917759 -0.2458964 0.2366963
#> h 0.02956075 -1.1775633 1.3182934
#> i 0.54982754 -0.9758506 0.5239098
#> j -2.27411486 1.0650573 0.6067480
## Reverse alphabetical names preserved
mefaTables(x, f, 1)
#> $xtab
#> [,1] [,2] [,3] [,4]
#> e 1 1 1 0
#> d 0 1 3 5
#> c 1 1 1 0
#> b 1 0 0 1
#> a 2 0 1 2
#>
#> $dtab
#> X1 X2 X3
#> e -0.2432367 -0.6650882 0.2841503
#> d 0.8620865 1.0743459 -1.4707363
#> c -1.9117205 0.2133557 -1.6994506
#> b 0.1181949 -0.3612213 0.4886288
#> a 0.5777091 2.6825572 0.1316706
#>
## Now result is the intersect
rownames(f) <- letters[3:12]
mefaTables(x, f, 1, xtab.fixed = FALSE)
#> $xtab
#> [,1] [,2] [,3] [,4]
#> e 1 1 1 0
#> d 0 1 3 5
#> c 1 1 1 0
#>
#> $dtab
#> X1 X2 X3
#> e -1.9117205 0.2133557 -1.6994506
#> d 0.1181949 -0.3612213 0.4886288
#> c 0.5777091 2.6825572 0.1316706
#>