The dataset has fillvalue of 1e30. While taking mean of the NetCDF files what code should i use? na.rm=TRUE or na.rm=FALSE( na.rm=FALSE)

list <- list.files("/filepath/", pattern = "*.nc", full.names = TRUE)
u2 <- stack(list)
r <- mean(u2, na.rm=TRUE)

I am getting values : -7.53555e+18, 1.263985e+18 (min, max) using na.rm=TRUE and -7.781048e+16, 3.923543e+15 (min, max) while coding withr <- mean(u2).

na.rm=TRUE does not give the correct result as the data are exaggerated. Another problem is that I am unable to plot the mean from first method (na.rm=FALSE) although the values seems to be quite correct. Before making analysis and plotting of the data what should be done?

As far as I know, the function list.files() returns a character vector, so I am surprised that mean(u2) returns a number at all. Have you shown your complete code?

Sorry..i missed one part. I updated the code. I was thinking if i should indicate that '1e30' is a missing number in the dataset. like NA <-1e30 Should i do that ? So that R understands that 1e30 is a missing number (NA) and not a value. R must be confused with the data values (1e16 to -4e17) is similar to NA value(1e30). How do i proceed?

If 1e30 is meant to represent NA, I would definitely replace it with NA. To give you detailed advice, it would be very helpful if you posted a Reproducible Example (Reprex). Since your problem has to do with doing calculations, I think you can do the Reprex by defining a small data frame containing a few rows of typical values of your data and then show how you do calculations on that. Here is a link to help you: