Related to this question Plotting netcdf file with levels in R
But I would like to know how to extract all levels from a netcdf file automatically, without going through one at a time. Do I have to write a custom function or is there a function in raster package that does that?