This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "R で音声入りのスライドを作る" | |
author: "@y__mattu" | |
date: "データ解析備忘録" | |
output: | |
xaringan::moon_reader: | |
css: "for_xaringan.css" | |
nature: | |
highlightStyle: github | |
highlightLines: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geopandas as gpd | |
from geopandas.geoseries import * | |
def reverse_geo(shdf, lon, lat): | |
""" | |
逆ジオコーディング | |
shdfは、geopandasでshapefileを読み込んだデータフレーム | |
lon, latは経度、緯度 | |
""" | |
polygon = shdf['geometry'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.fttsus.jp/worldgrids/ja/our_library/ | |
# calculate 3rd mesh code | |
cal_meshcode <- function(latitude, longitude){ | |
return(cal_meshcode3(latitude,longitude)) | |
} | |
# calculate 1st mesh code | |
cal_meshcode1 <- function(latitude, longitude){ | |
if(latitude < 0){ | |
o <- 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @param ... see RMeCab::RMeCabC() | |
#' @param pos 品詞(正規表現) | |
mecab_wakati2 <- function(..., pos = "") { | |
res <- RMeCabC(...) %>% | |
map(function(x) { | |
if(str_detect(names(x), pos) == TRUE) { | |
return(x[[1]]) | |
} else { | |
"" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Rcpp.h> | |
#include <mecab.h> | |
using namespace Rcpp; | |
using namespace MeCab; | |
// [[Rcpp::export]] | |
Rcpp::DataFrame executeMecab(std::string str, std::string tagger_opt) { | |
std::vector<std::string> surface, feature; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(sf) | |
# 関数 | |
## 都道府県抽出 | |
#' @param sp_polygon object of class sf, sfc or sfg | |
#' @param lon longitude | |
#' @param lat latitude | |
find_pref <- function(sp_polygon, lon, lat) { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MeCabの{Rcpp}ラッパー定義 | |
Sys.setenv("PKG_LIBS" = "-lmecab") | |
callRcppMecab <- Rcpp::cppFunction( | |
code = ' | |
Rcpp::DataFrame executeMecab(std::string str, std::string tagger_opt) { | |
using namespace Rcpp; | |
using namespace MeCab; | |
std::vector<std::string> surface, feature; | |
MeCab::Tagger *tagger = MeCab::createTagger(tagger_opt.c_str()); | |
const MeCab::Node *node(tagger->parseToNode(str.c_str())); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(RSelenium) | |
library(sf) | |
library(magrittr) | |
library(tidyverse) | |
download_smallshape <- function(pref, city, download_dir = "~/Downloads") { | |
rD <- rsDriver(verbose = FALSE) # Connecting to remote server | |
remDr <- rD[["client"]] | |
remDr$navigate("http://e-stat.go.jp/SG2/eStatGIS/page/download.html") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 住所(市)判定 | |
#' @param sp_polygon object of class sf, sfc or sfg | |
#' @param lon longitude | |
#' @param lat latitude | |
find_city <- function(sp_polygon = df, lon = lon, lat = lat) { | |
which.row <- sf::st_contains(sp_polygon, sf::st_point(c(lon, lat)), sparse = FALSE) %>% | |
grep(TRUE, .) | |
if (identical(which.row, integer(0)) == TRUE) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options cmplib = sasfunc.functions; | |
data foo; | |
input customer_number lat long; | |
datalines; | |
1 35.039200 135.728965 /* 金閣寺 */ | |
2 35.626065 139.884678 /* ディズニーシー */ | |
3 35.649114 139.742946 /* 慶應義塾大学 */ | |
; | |
run; |