You don't need to create a special function to do what you want, you can pass na.rm=TRUE
to tapply
:
Alltubes <- tapply(datIn$Material.loss.interval,
list(as.factor(datIn$Measurement.location),
as.factor(datIn$Tube.number)),
sd, na.rm=TRUE)
Then you can use:
par(mfrow=c(2,2), mar=c(4,4,1,1), oma=c(1,1,1,1))
boxplot(Alltubes, names=colnames(Alltubes), xlab="Tube numbers",
ylab="standard deviation")
boxplot(t(Alltubes), names=rownames(Alltubes),
xlab="Measurement locations", ylab="standard deviation")
matplot(colnames(Alltubes), t(Alltubes), xlab="Tube numbers",
ylab="standard deviation", type="b", lty=1, pch=19)
matplot(rownames(Alltubes), Alltubes, xlab="Measurement locations",
ylab="standard deviation", type="b", lty=1, pch=19)