Description Usage Arguments Value Examples
View source: R/Price_FUNCTIONS.R
Take a pair of columns, distinguished with suffix .x and .y, and merge them into a single column without suffixes. This is helpful for post-processing the output of pairwise price calculations.
1 | group.columns(x, gps, drop = F)
|
x |
A data frame |
gps |
A list of grouping column(s) |
drop |
Drop original, unpaired columns after grouping? TRUE/FALSE |
This function returns a data frame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # Data frame containing multiple communities we want to compare
set.seed(36)
cms1<-data.frame(comm.id=sort(rep(seq(1,3),6)),
species=rep(LETTERS[seq(1,6)],3),
func=rpois(6*3,lambda = 2))
cms2<-data.frame(comm.id=sort(rep(seq(1,3),6)),
species=rep(LETTERS[seq(1,6)],3),
func=rpois(6*3,lambda = 2))
cms1$site<-'site1'
cms2$site<-'site2'
cms<-rbind(cms1,cms2)
#Identify one grouping columns
cmsA<-group_by(cms,comm.id)
# Perform pairwise comparisons of all communities in cms identified by comm.id
ppA<-pairwise.price(cmsA,species='species',func='func')
# Process results using group.columns
group.columns(ppA,gps='comm.id')
group.columns(ppA,gps='comm.id',drop=T)
# Or with two grouping columns:
cmsB<-group_by(cms,comm.id,site)
ppB<-pairwise.price(cmsB,species='species',func='func')
# Process results using group.columns
group.columns(ppB,gps=c('comm.id'))
group.columns(ppB,gps=c('comm.id','site'))
group.columns(ppB,gps=c('comm.id','site'),drop=T)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.