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. Use smoothed TS relationship to nudge questionable data.
# This is perhaps a silly idea, but at least it illustrates
# how to write a nontrivial 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