Skip to contents

Specify which columns to use to produce a table with sample sizes. Helpful to visualize number of samples in your data.

Usage

sample_size(data, dim_1, dim_2, count)

Arguments

data

The data frame you want to calculate sample sizes for.

dim_1

The first dimension to calculate sample sizes for. This will be the resulting row names. This must be the column name within data.

dim_2

The second dimension to calculate sample sizes for. This will be the resulting column names. This must be the column name within data.

count

The column name within data that you wish to count the length of in order to calculate the sample sizes.

Value

A data frame of sample sizes.

Examples

Year <- c("2000", "2000", "2000", "2000", "2000", "2001", "2001", "2001", "2001",
"2002", "2002", "2002", "2002", "2003", "2003", "2003", "2003", "2003", "2003")
Site <- c("site1", "site1", "site2", "site2", "site2","site1", "site1", "site2",
          "site2", "site1", "site1", "site2", "site2","site1", "site1", "site2",
          "site2", "site2", "site2")
Quadrat <- c("Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Q9", "Q10", "Q11",
             "Q12", "Q13", "Q14", "Q15", "Q16", "Q17", "Q18", "Q19")
Cover <- sample(x = seq(from = 0, to = 1, by = 0.01), 19, replace = TRUE)
coral_cover <- data.frame(Year, Site, Quadrat, Cover)

sample_size(coral_cover, dim_1 = "Site", dim_2 = "Year", count = "Quadrat")
#>       2000 2001 2002 2003
#> site1    2    2    2    2
#> site2    3    2    2    4