[英]How to find specific longitude in 0 to 360 longitude range in R
我有一个netcdf文件,所有正经范围是0到360。我需要对澳大利亚相邻的太平洋区域范围从130E到180进行子集化。如何在R中进行子设置时以所有正经度提及我的经度范围。
After loading your lon dimension from the nc file, something like: 从nc文件加载lon尺寸后,如下所示:
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] 现在,您只需要打开变量,例如,尺寸为[lon,lat,time]的T2M(温度为2米)
T2M_Australia<-T2M[m:n,,]
Voila, you've just cropped your data. 瞧,您刚刚裁剪了数据。
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.