R/subset_data.R
subset_data.Rd
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")
x | data frame or |
---|---|
from | numeric. Defines the lower bound(s) of the data to subset.
Subsetting is based on the argument: |
to | numeric. Defines the upper bound(s) of the data to subset.
Subsetting is based on the argument: |
by | string. "time", "row", "o2" or "proportion". |
A data.table
or inspect
object.
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.
#> Warning: data set ‘squid.rd’ not foundx <- 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"#> Error in plot(x): object 'x' not found#> Warning: data set ‘flowthrough.rd’ not foundsubset_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"#> Warning: data set ‘sardine.rd’ not foundsubset_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"#> Warning: data set ‘sardine.rd’ not foundsubset_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"#> Warning: data set ‘flowthrough.rd’ not foundsubset_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"#> Warning: data set ‘sardine.rd’ not found#> Error in subset_data(sardine.rd, from = 94, to = 91, by = "o2") %>% auto_rate(): could not find function "%>%"