subset-section-method: Subset a section Object

subset,section-methodR Documentation

Subset a section Object

Description

Return a subset of a section object.

Usage

## S4 method for signature 'section'
subset(x, subset, ...)

Arguments

x

a section object.

subset

an optional indication of either the stations to be kept, or the data to be kept within the stations. See “Details”.

...

optional arguments, of which only the first is examined. The possibilities for this argument are indices, which must be a vector of station indices (see Example 6), or within, which must be a list or data frame, containing items named either x and y or longitude and latitude (see Example 7). If within is given, then subset is ignored.

Details

This function is used to subset data within the stations of a section, or to choose a subset of the stations themselves. The first case is handled with the subset argument, while the second is handled if ... contains a vector named indices. Either subset or indices must be provided, but not both.

In the "subset" method, subset indicates either stations to be kept, or data to be kept within the stations.

The first step in processing is to check for the presence of certain key words in the subset expression. If distance is present, then stations are selected according to a condition on the distance (in km) from the first station to the given station (Example 1). If either longitude or latitude is given, then stations are selected according to the stated condition (Example 2). If stationId is present, then selection is in terms of the station ID (not the sequence number) is used (Example 3). In all of these cases, stations are either selected in their entirety or dropped in their entirety.

If none of these keywords is present, then the subset expression is evaluated in the context of the data slot of each of the CTD stations stored within x. (Note that this slot does not normally contain any of the keywords that are listed in the previous paragraph; it does, then odd results may occur.) Each station is examined in turn, with subset being evaluated individually in each. The evaluation produces a logical vector. If that vector has length 1 (Examples 4 and 5) then the station is retained or discarded, accordingly. If the vector is longer, then the logical vector is used as a sieve to subsample that individual CTD profile.

In the "indices" method, stations are selected using indices, which may be a vector of integers that indicate sequence number, or a logical vector, again indicating which stations to keep.

Value

A section object.

Sample of Usage

# Example 7. Subset by a polygon determined with locator()
par(mfrow=c(2, 1))
plot(section, which="map")
bdy <- locator(4) # choose a polygon near N. America
GS <- subset(section, within=bdy)
plot(GS, which="map")

Author(s)

Dan Kelley

See Also

Other functions that subset oce objects: subset,adp-method, subset,adv-method, subset,amsr-method, subset,argo-method, subset,cm-method, subset,coastline-method, subset,ctd-method, subset,echosounder-method, subset,lobo-method, subset,met-method, subset,oce-method, subset,odf-method, subset,rsk-method, subset,sealevel-method, subset,topo-method, subset,xbt-method

Other things related to section data: [[,section-method, [[<-,section-method, as.section(), handleFlags,section-method, initializeFlagScheme,section-method, plot,section-method, read.section(), section, section-class, sectionAddStation(), sectionGrid(), sectionSmooth(), sectionSort(), summary,section-method

Examples

library(oce)
data(section)

# Example 1. Stations within 500 km of the first station
starting <- subset(section, distance < 500)

# Example 2. Stations east of 50W
east <- subset(section, longitude > (-50))

# Example 3. Gulf Stream
GS <- subset(section, 113 <= stationId & stationId <= 129)

# Example 4. Only stations with more than 5 pressure levels
long <- subset(section, length(pressure) > 5)

# Example 5. Only stations that have some data in top 50 dbar
surfacing <- subset(section, min(pressure) < 50)

# Example 6. Similar to #4, but done in more detailed way
long <- subset(section,
    indices = unlist(lapply(
        section[["station"]],
        function(s) 5 < length(s[["pressure"]])
    ))
)


oce documentation built on Sept. 11, 2024, 7:09 p.m.