# NOT RUN {
library(oce)
data(section)
stn <- section[["station", 100]]
# 1. Default: anything not flagged as 2 is set to NA, to focus
# solely on 'good', in the World Hydrographic Program scheme.
STN <- handleFlags(stn)
data.frame(old=stn[['salinity']], flag=stn[['salinityFlag']], new=STN[['salinity']])
# 2. A less restrictive case: include also 'questionable' data,
# and only apply this action to salinity.
STN <- handleFlags(stn, flags=list(salinity=c(1, 4:9)))
# 3. A Canadian Department of Fisheries and Oceans convention for
# some of its data files lists flags as 0=unchecked, 1=good,
# 2=uncertain, 3=doubtful, 4=wrong, and 5=changed, so a
# trusting arrangement would be to discard 2:4, and a more
# cautious approach would be to also discard 0.
STN <- handleFlags(stn, flags=list(2:4))
STN <- handleFlags(stn, flags=list(c(0,2:4)))
# 4. Use smoothed TS relationship to nudge questionable data.
# This is not a recommended procedure, but rather just a simple
# illustration of how to supply a function for an action.
f<-function(x) {
S <- x[["salinity"]]
T <- x[["temperature"]]
df <- 0.5 * length(S) # smooths a bit
sp <- smooth.spline(T, S, df=df)
0.5 * (S + predict(sp, T)$y)
}
par(mfrow=c(1,2))
STN <- handleFlags(stn, flags=list(salinity=c(1,3:9)), action=list(salinity=f))
plotProfile(stn, "salinity", mar=c(3, 3, 3, 1))
p <- stn[['pressure']]
par(mar=c(3, 3, 3, 1))
plot(STN[['salinity']] - stn[['salinity']], p, ylim=rev(range(p)))
# }
Run the code above in your browser using DataLab