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
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"]]))
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
hist(T_all,col = "yellow",border = "black",main = "A Histogram of depthwise Temperature",xlab = "Temperature",ylab = "count")
S_all <- unlist(lapply(casts, function(x) x[["salinity"]]))
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
hist(S_all,col = "yellow",border = "black",main = "A Histogram of depthwise Salinity",xlab = "Salinity",ylab = "count")