博文

空间插值 sf对象

 library(sf) library(gstat) library(openxlsx) library(magrittr) library(tidyverse) mycrs <- '+proj=lcc +lat_0=0 +lon_0=105 +lat_1=30 +lat_2=62 +x_0=0 +y_0=0 +ellps=krass +units=m +datum=WGS84 +no_defs' data_jiangshui <- read.xlsx('./Documents/wang_map/降水2005-2009修订后.xlsx') gs_station<- st_read("./Documents/wang_map/甘肃站点.shp")  %>%    st_transform(mycrs) gs_station %<>%    inner_join(data_jiangshui,by=c('stationid'='stationid'))  gs<- st_read("./Documents/wang_map/town_62.shp") %>%    st_transform(mycrs) gs.border <- st_boundary(gs) gs.bou <- st_union(gs) %>%    st_boundary() plot(gs.bou) grid <- st_make_grid(gs.bou, n = c(50, 50)) %>%    st_transform(st_crs(gs_station)) plot(grid) st_crs(gs_station)$proj4string st_crs(grid)$proj4string vg.gs <- variogram(gs_station$`2005-7` ~ 1, gs_station) # vg.gs # plot(vg.gs$dist, vg.gs$gamma) # vgm.gs <- vgm(80, "Gau", 500,nugget=200) fit.gs...

空间插值 autoKrige

 library(automap) library(tidyverse) library(openxlsx) library(magrittr) library(raster) library(sf) mycrs <- '+proj=lcc +lat_0=0 +lon_0=105 +lat_1=30 +lat_2=62 +x_0=0 +y_0=0 +ellps=krass +units=m +datum=WGS84 +no_defs' gansu <- st_read("~/wang_map/甘肃站点.shp") jiangshui <- read.xlsx('~/wang_map/降水2005-2009修订后.xlsx') gansu %<>%    inner_join(jiangshui,by=c('stationid'='stationid')) %>%   st_transform(crs=mycrs) %>%    as_Spatial()  gsmap <- st_read("~/wang_map/town_62.shp") %>%    st_transform(crs=mycrs) %>%    as_Spatial()  #甘肃轮廓融合 # gsmapline <- rgeos::gUnaryUnion(gsmap) grd <- makegrid(gsmap, n = 10000) names(grd) <- c("X", "Y") gridded(grd)  <- ~ X+Y # Create SpatialPixel object plot(grd) # coordinates(grd) <- c("X", "Y") # gridded(grd) <- TRUE  # Create SpatialPixel object # fullgrid(grd)  ######### 泛克里金法grd需要指定 grd <- as.data.frame(spsample(...

na替换0

 mutate(across(everything(), ~replace_na(.x, 0)))

R 多列类型转换

mutate_at(vars(contains("数")),as.numeric)    mutate_if(str_detect(colnames(.), "数"),as.numeric)  mutate_if(is.character,as.numeric)   在dplyr中,选择包含“ Sepal”的变量,并将NA分配给Species为“ setosa”的那些行:   iris %>%     mutate_at(vars(contains("Sepal")), funs(ifelse(Species == "setosa", NA, .)))    iris %>%     mutate_at(vars(contains("Sepal")),                funs(na_if(Species, "setosa")))

pip conda you-get 使用代理

 pip install --proxy http://127.0.0.1:7890 pandas --upgrade conda config --set proxy_servers.http  http://127.0.0.1:7890 you-get -x 127.0.0.1:7890 'https://www.youtube.com/watch?v=jNQXAC9IVRw'

R proxy

Sys.setenv(http_proxy = "http://127.0.0.1:8001") Sys.setenv(https_proxy = "https://127.0.0.1:8001")

分组抽样

 library(sampling) sam_group <- strata(dat,stratanames = 'xiangzhen',size = seq(1:20),method = 'srswr') sam_group <- strata(dat,stratanames = 'xiangzhen',size = rep(3,20),method = 'srswr') #分组抽样 sam_group <- dat %>%    filter(weihao !='000') %>%    group_by(xiangzhen) %>%    slice(sample(3))