我在某些天气变量(如maxT和minT)上有纬度和经度的每日数据。我希望从这些数据中重新采样,以便如果选择一天中的纬度/长度在样本中,则此纬度/长度(邻居)的300公里范围内的所有纬度/长度也应该是样本的一部分。我不知道该怎么做。到目前为止,我已经使用spdep包中的命令dnearneigh来识别每个纬度/长度300 kms内的纬度/长度。
提前感谢您的帮助。这是我的示例数据和R代码。
dput(head(rad_aod_temp_daily,1))
structure(list(latitude = 23L, longitude = 68L, year = 2000L,
month = 11L, day = 21L, xygrid_id = 632L, solar_rad = 2.070422,
aod = 0.27, day_of_season = 1L, cntry = structure(1L, .Label = "India", class = "factor"),
state = structure(2L, .Label = c("Bihar", "Gujarat", "Haryana",
"Madhya Pradesh", "Maharashtra", "Punjab", "Rajasthan", "Uttar Pradesh"
), class = "factor"), log_sr = 0.7277523, time = 1L, time2 = 1L,
date = structure(1275L, .Label = c("01-Apr-01", "01-Apr-02",
"01-Apr-03", "01-Apr-04", "01-Apr-05", "01-Apr-06", "01-Apr-07",
"01-Apr-08", "01-Apr-09", "01-Apr-10", "01-Apr-11", "01-Apr-12",
"01-Apr-13", "01-Dec-00", "01-Dec-01", "01-Dec-02", "01-Dec-03",
"01-Dec-04", "01-Dec-05", "01-Dec-06", "01-Dec-07", "01-Dec-08",
"01-Dec-09", "01-Dec-10",class = "factor"), maxt = 31.22, mint = 16.11,
meant = 23.67), .Names = c("latitude", "longitude", "year",
"month", "day", "xygrid_id", "solar_rad", "aod", "day_of_season",
"cntry", "state", "log_sr", "time", "time2", "date", "maxt",
"mint", "meant"), row.names = 1L, class = "data.frame")
library(spdep)
coords <- as.matrix(cbind(rad_aod_temp_daily$longitude,rad_aod_temp_daily$latitude))
nlist <- dnearneigh(coords, d1=0,d2=300,longlat=TRUE)
答案 0 :(得分:1)
在确定符合条件的案例后,创建一个新数据框并引导该数据框。
#create data frame
X1=rnorm(1000,0,1)
X2=rnorm(1000,0,1)
df=cbind(X1,X2)
#create indicator to bootstrap
df$indicator=ifelse(X1>.75,1,0) #I select only cases greater than .75 on X1
df.new=df[df$indicator==1,]
在你创建了df.new boostrap这些数据之后。