Skip to content

Instantly share code, notes, and snippets.

View swsoyee's full-sized avatar
💤
zzZ...

InfinityLoop swsoyee

💤
zzZ...
View GitHub Profile
R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
@swsoyee
swsoyee / shim.R
Created September 23, 2020 13:41 — forked from wch/shim.R
Shim system.file for htmlwidgets so that a dependent package can be used with devtools::load_all()
shim_system_file <- function(package) {
imports <- parent.env(asNamespace(package))
pkgload:::unlock_environment(imports)
imports$system.file <- pkgload:::shim_system.file
}
shim_system_file("htmlwidgets")
shim_system_file("htmltools")
# After the code above has been run, you can load an in-development package
Nothing
@swsoyee
swsoyee / extract_pcr_data_from_pdf.R
Created April 30, 2020 14:26
都道府県別・PCR検査実施人数の累計PDFからデータ抽出
library(tabulizer)
library(data.table)
library(purrr)
location <- "https://www.mhlw.go.jp/content/10900000/000626159.pdf"
out <- extract_tables(location)
final <- do.call(rbind, out[length(out)])
dt <- data.table(final)
@swsoyee
swsoyee / test_anther_cluster.R
Created April 4, 2020 05:06
尝试用点图做cluster,
signateDetail<- fread(paste0(DATA_PATH, 'SIGNATE COVID-2019 Dataset - 罹患者.csv'), header = T)
signateDetail$公表日 <- as.Date(signateDetail$公表日)
signateDetail[, 受診都道府県 := gsub('県', '', 受診都道府県)]
signateDetail[, 受診都道府県 := gsub('府', '', 受診都道府県)]
signateDetail[, 受診都道府県 := gsub('東京都', '東京', 受診都道府県)]
signateDetail[, regionId := paste0(都道府県コード, '-', 都道府県別罹患者No)]
oldYear <- c('0 - 9', '10 - 19', '20 - 29', '30 - 39', '40 - 49', '50 - 59', '60 - 69', '70 - 79', '80 - 89', '-90', '非公表', '', NA)
newYear <- c(10, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 100, 100)
names(oldYear) <- newYear
@swsoyee
swsoyee / 使用外部IDE编写游猴脚本.md
Created January 8, 2020 08:17
使用外部IDE编写游猴脚本

Mac

在游猴中新建一个脚本,然后在头部信息中引用外部文件即可(前提是在Chrome的游猴插件中设置了允许插件访问本地文件后)。

// @require     file:/*.js
@swsoyee
swsoyee / index.js
Created November 25, 2019 06:31 — forked from MoOx/index.js
Export/import github labels
// go on you labels pages
// eg https://github.com/cssnext/cssnext/labels
// paste this script in your console
// copy the output and now you can import it using https://github.com/popomore/github-labels !
var labels = [];
[].slice.call(document.querySelectorAll(".label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
@swsoyee
swsoyee / extract_lines_in_captioning_file.R
Last active December 23, 2018 06:40
抽取字幕文件(ASS, SRT)中的含有かな的台词(包含上下文)
file <- list.files()
file <- file[grepl("(.ass)|(.ASS)|(.srt)|(.SRT)$", file)]
if (length(file) > 0) {
output <- sapply(file, function(x) {
text <- readLines(x, encoding = "UTF-8")
if(grepl(pattern = "(.srt)|(.SRT)$", x = x)) {
text.1 <- strsplit(x = paste0(text, collapse = "&"), split = "&&")
text <- gsub("&", " ", text.1[[1]])
@swsoyee
swsoyee / calculate_MA_value_of_two_group.r
Created May 4, 2018 01:33
Input a RowCount data frame and group label vector, return a data frame of MA value.
calMAValue <- function(data, data.cl){
group <- levels(factor(data.cl))
if (length(group) == 2) {
#遺伝子ごとにG1群とG2の平均の対数を計算した結果
mean_G1 <- log2(apply(as.matrix(data[,data.cl==group[1]]), 1, mean))
mean_G2 <- log2(apply(as.matrix(data[,data.cl==group[2]]), 1, mean))
#「G1群の平均値」と「G2群の平均値」の平均をとったものがM-A plotのA(x軸の値)に相当する
x_axis <- (mean_G1 + mean_G2)/2
#いわゆるlog比(logの世界での引き算)がM-A plotのM(y軸の値)に相当する
y_axis <- mean_G2 - mean_G1