1

I have one netcdf file with all positive longitude ranges from 0 to 360. I need to subset Australia adjacent Pacific region ranges from 130E to 180. How to mention my longitude range in all positive longitude while sub setting in R.

  • Please provide a reproducible example. It might help to read [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269/4996248) – John Coleman Aug 31 '18 at 00:11

2 Answers2

2

After loading your lon dimension from the nc file, something like:

lon<-nc$dim$lon$vals

Now you have to find the range of where the respective latitude and longitude lie at.

You can use:

m<-which(lon==130)
n<-which(lon==180)

Now you just have to open the variable, for instance, T2M(Temperature at 2 meters) having dimensions [lon,lat,time]

T2M_Australia<-T2M[m:n,,]

Voila, you've just cropped your data.

0

You'd need to post reproducible data (see the comment), but in general, this is how I would do it:

library(tidyverse)

data <- tibble(long_ranges = 1:360) %>%
 mutate(australia = if_else(long_ranges >= 130 & long_ranges <= 180,
                "australia",
                "not_australia")) %>%
filter(australia == "australia")
Ben G
  • 4,148
  • 2
  • 22
  • 42