Skip to contents

Sum columns containing unusable observations and remove rows that contain more than the specified cutoff number of unusable points. Helpful if there are annotations that were unidentifiable and you want to remove them from the total usable observations, and you can remove quadrats with too many unusable observations.

Usage

usable_obs(
  data,
  unusable,
  max = FALSE,
  cutoff,
  above_cutoff = FALSE,
  rm_unusable = TRUE
)

Arguments

data

A data frame with each row representing a sampling unit (ex. a quadrat or photo).

unusable

A vector of column names containing unusable observations.

max

If max = FALSE, no threshold will be examined. If max = TRUE, a threshold cutoff needs to be provided where rows containing more than the cutoff will be removed from the data frame.

cutoff

The threshold number where rows containing more unusable observations than the cutoff will be removed from the data frame.

above_cutoff

If above_cutoff = TRUE, the data frame returned will be the rows containing more unusable observations than the cutoff. If above_cutoff = FALSE the data frame returned will be the rows containing equal to or less unusable observations than the cutoff.

rm_unusable

If rm_unusable = TRUE, the columns named in the unusable vector will be removed from the data frame. These columns will not be removed if rm_unusable = FALSE, though duplicate data will remain.

Value

A data frame containing summed unusable points.

Examples

#create data set for example
Sites <- as.factor(c("One", "One", "Two", "Two", "Three", "Three"))
Transect <- as.factor(c("1-Shallow", "2-Shallow", "1-Shallow", "2-Shallow",
    "1-Shallow", "2-Shallow"))
Acropora.sp <- c(1, 2, 3, 4, 5, 6)
Gardineroseris.sp <- c(6, 1, 2, 3, 4, 5)
Psammocora.sp <- c(5, 6, 1, 2, 3, 4)
Leptastrea.sp <- c(4, 5, 6, 1, 2, 3)
Blurry <- c(3, 4, 5, 6, 1, 2)
Unk <- c(2, 3, 4, 5, 6, 1)
coral_cover <- data.frame(Sites, Transect, Acropora.sp, Gardineroseris.sp,
                          Psammocora.sp, Leptastrea.sp, Blurry, Unk)


usable_obs(coral_cover, c("Blurry", "Unk"))
#>   Sites  Transect Acropora.sp Gardineroseris.sp Psammocora.sp Leptastrea.sp
#> 1   One 1-Shallow           1                 6             5             4
#> 2   One 2-Shallow           2                 1             6             5
#> 3   Two 1-Shallow           3                 2             1             6
#> 4   Two 2-Shallow           4                 3             2             1
#> 5 Three 1-Shallow           5                 4             3             2
#> 6 Three 2-Shallow           6                 5             4             3
#>   unusable
#> 1        5
#> 2        7
#> 3        9
#> 4       11
#> 5        7
#> 6        3

usable_obs(coral_cover, c("Blurry", "Unk"), above_cutoff = TRUE)
#> Warning: no max specified
#>   Sites  Transect Acropora.sp Gardineroseris.sp Psammocora.sp Leptastrea.sp
#> 1   One 1-Shallow           1                 6             5             4
#> 2   One 2-Shallow           2                 1             6             5
#> 3   Two 1-Shallow           3                 2             1             6
#> 4   Two 2-Shallow           4                 3             2             1
#> 5 Three 1-Shallow           5                 4             3             2
#> 6 Three 2-Shallow           6                 5             4             3
#>   unusable
#> 1        5
#> 2        7
#> 3        9
#> 4       11
#> 5        7
#> 6        3

usable_obs(coral_cover, c("Blurry", "Unk"), rm_unusable = FALSE)
#> Warning: duplication exists in the data frame
#>   Sites  Transect Acropora.sp Gardineroseris.sp Psammocora.sp Leptastrea.sp
#> 1   One 1-Shallow           1                 6             5             4
#> 2   One 2-Shallow           2                 1             6             5
#> 3   Two 1-Shallow           3                 2             1             6
#> 4   Two 2-Shallow           4                 3             2             1
#> 5 Three 1-Shallow           5                 4             3             2
#> 6 Three 2-Shallow           6                 5             4             3
#>   Blurry Unk unusable
#> 1      3   2        5
#> 2      4   3        7
#> 3      5   4        9
#> 4      6   5       11
#> 5      1   6        7
#> 6      2   1        3

usable_obs(coral_cover, c("Blurry", "Unk"), max = TRUE, cutoff = 8)
#>   Sites  Transect Acropora.sp Gardineroseris.sp Psammocora.sp Leptastrea.sp
#> 1   One 1-Shallow           1                 6             5             4
#> 2   One 2-Shallow           2                 1             6             5
#> 3 Three 1-Shallow           5                 4             3             2
#> 4 Three 2-Shallow           6                 5             4             3
#>   unusable
#> 1        5
#> 2        7
#> 3        7
#> 4        3

usable_obs(coral_cover, c("Blurry", "Unk"), max = TRUE, cutoff = 8, above_cutoff = TRUE)
#>   Sites  Transect Acropora.sp Gardineroseris.sp Psammocora.sp Leptastrea.sp
#> 1   Two 1-Shallow           3                 2             1             6
#> 2   Two 2-Shallow           4                 3             2             1
#>   unusable
#> 1        9
#> 2       11