Articles by Dan Kelley Blog/R

Using the plyr package

January 18, 2014 | Dan Kelley Blog/R

Introduction The base R system provides lapply() and related functions, and the package plyr provides alternatives that are worth considering. It will be assumed that readers are familiar with lapply() and are willing to spend a few moments reading the plyr documentation, to see why the illustration here will use ... [Read more...]

Colourizing a trajectory

January 15, 2014 | Dan Kelley Blog/R

Introduction In Oceanography it can be useful to use colour to display z values along an (x,y) trajectory. For example, CTD data might be displayed in this way, with x being distance along track, y being depth, and z being temperature. This post shows how one might do this. ... [Read more...]

Butterworth filter overshoot

January 15, 2014 | Dan Kelley Blog/R

Introduction Butterworth filters with order other than 1 have an overshoot phenomenon that can be problematic in some cases. For example, if smoothing is used on an estimate of kinetic energy, overshoots might yield negative values that are nonphysical. This post simply illustrates this with made-up data that the reader can ... [Read more...]

Cabelling calculations

January 15, 2014 | Dan Kelley Blog/R

Abstract R code is provided in aide of laboratory demonstration of cabelling. Introduction Setting up a cabelling experiment requires creating two watermasses of equal density, and if only S and T can be measured, that means calculating densities. Using a TS diagram and graphical interpolation is one approach to that ... [Read more...]

Smoothing CTD profiles

January 11, 2014 | Dan Kelley Blog/R

Introduction Smoothing hydrographic profiles with conventional time-series methods is problematic for two reasons: (a) the data are commonly not equi-spaced in depth and (b) the data seldom lack trends in depth. The issues and their solutions are illustrated without much discussion here. The first step in making the graph shown ... [Read more...]

Inferring halocline depth

January 11, 2014 | Dan Kelley Blog/R

Introduction There are no agreed-upon methods for inferring halocline depth, but a reasonable method might involve locating the depth at which dS/dp is largest, where S is salinity and p is pressure (Kelley 2014 chapter 5). Calculating the derivative using e.g. diff(S)/diff(p) can be problematic because of ... [Read more...]

PISA scores

January 6, 2014 | Dan Kelley Blog/R

The Guardian Newspaper has an interesting article about the Pisa (Program for International Student Assessment) scores for 2012, and it includes data. Since I was interested to see how my own region scored, I downloaded the data into a file called PISA-summary-2012.csv and created a plot summarizing scores in all ... [Read more...]

Installing oce in R

December 30, 2013 | Dan Kelley Blog/R

Several of the blog items have used the oce package. The official version of this can be installed from within R by
1
install.packages("oce") and more up-to-date versions can be installed using the devtools package written by Hadley Wickham, which is itself installed with
1
install.packages("devtools") ... [Read more...]

R interface to WebTide

December 29, 2013 | Dan Kelley Blog/R

A previous posting explained how to install WebTide on an OSX machine. This one shows how to hook up to an installed WebTide database, so that R code can get tidal predictions. The following code in the R language will produce a graph in which the top panel mimics the ... [Read more...]

Sundial calculations

December 28, 2013 | Dan Kelley Blog/R

After experimenting with calculations for what I eventually came to realize were analemma-based sundials (with shadow cast by a vertical pole), I remembered that the common sundial has a wedge as the shadow-maker. A bit of research told me that the wedge is called a gnomon. It is a right ... [Read more...]

Analemma graphs

December 27, 2013 | Dan Kelley Blog/R

Continuing on the theme of solar angles, the code given below produces an analemma diagram similar to that of Lynch (2012, figure 2).
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(oce) loc [Read more...]

A new Oce coastline

December 22, 2013 | Dan Kelley Blog/R

Part 1: coastal applications The oce package has a world coastline file that is visibly crude on a scale suitable for continental-shelf work.  At the cost of about 1 Mbyte of storage, a candidate for a replacement is a 1:10million scale version downloaded from naturalearthdata.com (full link below). As illustrated below ... [Read more...]

Day length calculation

December 21, 2013 | Dan Kelley Blog/R

The winter solstice has been on many minds lately. The days are about to start getting longer … but just how fast will they do that? This post provides R that calculates and graphs day length and its variation, using uniroot() to find sunrises and sunsets as indicated by solar altitude ... [Read more...]

Solstice sunrise-sunset

December 21, 2013 | Dan Kelley Blog/R

Introduction The sunAngle() function in the oce package provides a handy way to determine sunrise/sunset azimuth angles, and this is used to find alignments for the winter solstice in Halifax, NS. Methods First, set up the problem; these may be the only lines that need editing for other places ... [Read more...]

Moon phase calculation

December 21, 2013 | Dan Kelley Blog/R

The illuminated fraction of the moon can be calculated with moonAngle() in the oce package, as illustrated graphically and in R code below.
1
2
3
4
5
6
7
library(oce) par(mar=c(3, 3, 1, 1), mgp=c(2, 0.7, 0)) # tighten margins t [Read more...]
1 2 3

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)