This function subsets a data frame or inspect() object based on a given set of rules. It can subset data based on ranges of: time, oxygen, row number, or proportion of total oxygen used. For data frames, to subset by 'time', 'o2', or 'proportion', the time data is assumed to be in the first column, and oxygen in the second column. For inspect() objects, the data will have been coerced to this structure already. The function can subset any data frame by 'row'.

subset_data(x, from, to, by = "time")

Arguments

x

data frame or inspect object. The data to subset.

from

numeric. Defines the lower bound(s) of the data to subset. Subsetting is based on the argument: by.

to

numeric. Defines the upper bound(s) of the data to subset. Subsetting is based on the argument: by.

by

string. "time", "row", "o2" or "proportion".

Value

A data.table or inspect object.

Details

For multiple column data frames, such as with time in column 1, and multiple columns of oxygen data, the subset object will include all columns. In the case of subsetting by = "o2", subsetting is based on the first column of oxygen data (i.e. column 2), and all subsequent columns are subset between the same rows regardless of oxygen values.

This function is ideal for passing only some regions of your data to other functions such as auto_rate, either by resaving them as a new object or through the use of pipes (%>%). It is also ideal for use with intermittent-flow data in loops, where each replicate can be extracted and passed to an analytical function such as calc_rate or auto_rate. See examples and vignettes.

Examples

# Subset by time: data("squid.rd")
#> Warning: data set ‘squid.rd’ not found
x <- subset_data(squid.rd, from = 2000, to = 4000, by = "time")
#> Error in subset_data(squid.rd, from = 2000, to = 4000, by = "time"): could not find function "subset_data"
plot(x)
#> Error in plot(x): object 'x' not found
data("flowthrough.rd")
#> Warning: data set ‘flowthrough.rd’ not found
subset_data(flowthrough.rd, from = 50, to = 600, by = "time")
#> Error in subset_data(flowthrough.rd, from = 50, to = 600, by = "time"): could not find function "subset_data"
# Subset by O_2: data("sardine.rd")
#> Warning: data set ‘sardine.rd’ not found
subset_data(sardine.rd, from = 94, to = 91, by = "o2")
#> Error in subset_data(sardine.rd, from = 94, to = 91, by = "o2"): could not find function "subset_data"
# Subset by proportion of total oxygen used: data("sardine.rd")
#> Warning: data set ‘sardine.rd’ not found
subset_data(sardine.rd, from = 0.8, to = 0.4, by = "proportion")
#> Error in subset_data(sardine.rd, from = 0.8, to = 0.4, by = "proportion"): could not find function "subset_data"
# Subset by row: data("flowthrough.rd")
#> Warning: data set ‘flowthrough.rd’ not found
subset_data(flowthrough.rd, from = 10, to = 750, by = "row")
#> Error in subset_data(flowthrough.rd, from = 10, to = 750, by = "row"): could not find function "subset_data"
# Pass (via piping) only part of a dataset to auto_rate data("sardine.rd")
#> Warning: data set ‘sardine.rd’ not found
subset_data(sardine.rd, from = 94, to = 91, by = "o2") %>% auto_rate()
#> Error in subset_data(sardine.rd, from = 94, to = 91, by = "o2") %>% auto_rate(): could not find function "%>%"