# WBGT (calculating wet bulb globe temperature)

#1

Hi all,

Is there anyone who is experienced with using the WBGT function in RStudio?
The formula itself seems rather straightforward, and I have all necessary data.
However, when I compute the function, I only get many N/A's. I have no clue how to fix this problem; who has any suggestions or help?

Best,
Mike

#2

Hey @MikeM, calculating WBGT is my bread-and-butter I'm not familiar with a function for calculating it built into RStudio, though. Is this a package or Addin that's been installed on your system?

#3

Oh! You're the expert I am looking for haha!

#4

Mm, that's an interesting package—someone wrapped an existing C library. That could be tricky to debug. If you want to use it, I'd suggest getting in touch with the package author (maybe file an issue?)

One thing I notice, quickly scanning the wrapper code, is that it does some error checking on pressure:

``````out[pres > 2000 | pres < 800] <- NA
``````

I would be checking what units the code expects for pressure—particularly if the authors are US-based. If you're feeding in mm of mercury and they're expecting hectopascals or kilopascals (or vice-versa), that could lead to a heap of `NA`s.

Honestly, you might just find it easier to do yourself in R—I've calculated sWBGT (a simplified version that assumes sunny conditions) in R on tens of thousands of rows without a problem. It only requires element-wise operations (adding different columns directly across rows), so R will handle it fine.

One gotcha when I do daily aggregations of WBGT (eg. daily max WBGT), I often forget the `na.rm = TRUE` argument in aggregation functions like `pmax` or `max`. So if you give them data with any missing values, the whole thing comes out `NA`, and then I wonder why I have so many `NA`s in my output

Hope that helps!