ApplyByClass: Apply by class

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/community.R

Description

Apply functions to a group of values given by a node property.

Usage

1
2
3
4
ApplyByClass(community, property, class, fn, ...)
SumMByClass(community, class, na.rm=FALSE)
SumNByClass(community, class, na.rm=FALSE)
SumBiomassByClass(community, class, na.rm=FALSE)

Arguments

community

an object of class Community.

property

the property to which fn is applied.

class

the property over which fn is applied. Defaults to 'category' if the community has a node property with that name.

fn

a function.

na.rm

logical - if TRUE then NA values are removed.

...

Other parameters to fn.

Details

ApplyByClass applies fn to property by class. property and class should both be names that meet the criteria of the properties argument of NPS.

SumMByClass, SumNByClass and SumBiomassByClass are convenient wrapper around ApplyByClass.

Value

A vector or list of values, named by unique values of class.

Author(s)

Lawrence Hudson

See Also

Community, NPS

Examples

 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
31
data(TL84)

# Sum body mass by category
ApplyByClass(TL84, 'M', 'category', sum)

# A more convenient way to sum body mass by category
SumMByClass(TL84)

# Sum body mass by kingdom. The 'Unclassified flagellates' node does not have a 
# kingdom, so we get a value labelled '<unnamed>'.
SumMByClass(TL84, 'kingdom')

# Maximum body mass by category
ApplyByClass(TL84, 'M', 'category', max)

# A list of min and max M
ApplyByClass(TL84, 'M', 'category', range)

# A list of min and max M by kingom
ApplyByClass(TL84, 'M', 'kingdom', range)

# The same values as a matrix
do.call('rbind', ApplyByClass(TL84, 'M', 'kingdom', range))

# Broadstone Stream has some nodes in every category without M so all returned 
# values are NA.
data(BroadstoneStream)
SumMByClass(BroadstoneStream)

# Get rid of the NA values
SumMByClass(BroadstoneStream, na.rm=TRUE)

Example output

invertebrate     producer    vert.ecto 
5.110800e-07 1.127248e-09 3.470000e-03 
invertebrate     producer    vert.ecto 
5.110800e-07 1.127248e-09 3.470000e-03 
   <unnamed>     Animalia     Bacteria    Chromista      Plantae     Protozoa 
3.460000e-13 3.470511e-03 1.736800e-11 9.488933e-10 1.054600e-11 1.500950e-10 
invertebrate     producer    vert.ecto 
    3.00e-07     8.31e-10     1.29e-03 
$invertebrate
[1] 1e-11 3e-07

$producer
[1] 3.03e-14 8.31e-10

$vert.ecto
[1] 0.00101 0.00129

$`<unnamed>`
[1] 3.46e-13 3.46e-13

$Animalia
[1] 1.00e-11 1.29e-03

$Bacteria
[1] 1.32e-13 1.62e-11

$Chromista
[1] 3.03e-14 8.31e-10

$Plantae
[1] 2.37e-13 4.30e-12

$Protozoa
[1] 1.75e-13 6.46e-11

              [,1]     [,2]
<unnamed> 3.46e-13 3.46e-13
Animalia  1.00e-11 1.29e-03
Bacteria  1.32e-13 1.62e-11
Chromista 3.03e-14 8.31e-10
Plantae   2.37e-13 4.30e-12
Protozoa  1.75e-13 6.46e-11
   <unnamed> invertebrate     producer 
          NA           NA           NA 
   <unnamed> invertebrate     producer 
     0.00000     31.37048      0.00000 

cheddar documentation built on Feb. 13, 2020, 5:07 p.m.