Often we need to work with multiple CTD casts to summerise the properties like temperature,salinity,density etc. of a large scale water column.From the code below we can extract a single variable from all the CTD casts.

library(oce) #load the oce package

files<- dir("D:/Projects/Liberia/Products/R studio/Data/Seabird_data",pattern = "*.cnv") #get all the .cnv file from the directory

casts<- list() #make a list dataframe
for (ifile in 1:length(files)) {
  casts[[ifile]]<- read.oce(files[ifile]) 
}
str(casts,1) #first level summary
## List of 4
##  $ :Formal class 'ctd' [package "oce"] with 3 slots
##  $ :Formal class 'ctd' [package "oce"] with 3 slots
##  $ :Formal class 'ctd' [package "oce"] with 3 slots
##  $ :Formal class 'ctd' [package "oce"] with 3 slots

Now,we want to extract all the temperature measurements from each object in our new list.

method-1

T_all <- NULL
for (i in 1:length(casts)) {
  T_all<- c(T_all,casts[[i]][["temperature"]])
}

method-2

T_all <- unlist(lapply(casts, function(x) x[["temperature"]]))

Now,we can summarise all the temperature value

summary(T_all)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   4.948   6.348  12.275  13.325  20.867  22.851       1

Now,plot a histogram of the temperature extracted from all the ctd casts

hist(T_all,col = "yellow",border = "black",main = "A Histogram of depthwise Temperature",xlab = "Temperature",ylab = "count")

Again,we can extract the salinity values from the list file we created.In this case,we use the second method.

S_all <- unlist(lapply(casts, function(x) x[["salinity"]]))

Now,we can summarise all the salinity value

summary(S_all)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   34.57   34.68   35.18   35.09   35.46   35.82       1

Now,plot a histogram of the salinity extracted from all the ctd casts

hist(S_all,col = "yellow",border = "black",main = "A Histogram of depthwise Salinity",xlab = "Salinity",ylab = "count")