Skip to content

Instantly share code, notes, and snippets.

library(rvest)
url <- "https://kuochang.tw/quote"
res <- read_html(url)
onion.quotations <-
res |>
html_elements("div.quoteCard") |>
html_elements("span.line") |>
html_text() |>
trimws() |>
(\(x) {gsub("[\t\n\r ,。]+", ",", x)})()
library(tidyverse)
set.seed(1234)
d <-
tibble(
Time = letters[1:5] %>% rep(3),
Species = LETTERS[1:3] %>% rep(each = 5),
LS_2 = rpois(15, 1),
LS_3 = rpois(15, 2),
LS_4 = rpois(15, 3)
)
# 兩個獨立常態母體,4個參數 mu1 mu2 sigma1 sigma2 未知。各自隨機抽n1和n2個樣本,想知道(mu2 - mu1) / sigma1的抽樣分布。
library(magrittr)
library(data.table)
library(ggpubr)
# 單次模擬的function
sim <-
function(mu1 = 10,
mu2 = 10,
library(rbenchmark)
library(Matrix)
ncol <- 2e3
nrow <- 1e3
x <- matrix(rbinom(ncol * nrow, 1, 0.1), nrow = nrow, ncol = ncol)
benchmark(
which(x != 0, arr.ind = T), # method 0
which(Matrix(x, sparse = T) != 0, arr.ind = T), # method 1
@chenpanliao
chenpanliao / code.tex
Last active June 20, 2021 10:31
文章代碼(AID): #1WpQhwq- (LaTeX) [ptt.cc] [問題] 求latex大神幫解這個code
\documentclass[]{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[!t]
\centering
\caption{Table to test captions and labels.}
\begin{tabular}{p{1.2cm}lllll} % 1.2cm調到"Output:"放得下就行
\toprule
Input: & \multicolumn{5}{l}{Tap weight vector}\\
Sys.setlocale(locale = "cht") # for windows os
library(magrittr)
library(ggpubr)
library(data.table)
p.sensitive <- c(0.8, 0.9, 0.999999)
p.specific <- c(0.9, 0.99, 0.999, 0.9999)
p.prevalence.rate <-
c(
seq(0.000001, 0.000009, 0.0000001),
@chenpanliao
chenpanliao / shinyApp.R
Created June 24, 2020 16:58
shinyApp.R
library(shiny)
library(rsconnect)
library(shinyjs)
ui <- shinyUI(fluidPage(
titlePanel("index predictive plot and predictive table"),
mainPanel(
textInput("index1", label = "code") ,
textOutput("yahooop"),
actionButton("goButton", "Go!"),
@chenpanliao
chenpanliao / code.R
Last active June 23, 2020 14:41
時間序列 forecast()相關問題
library(tseries)
library(quantmod)
library(forecast)
library(car)
library(haven)
index3 <- getSymbols("^TWII", auto.assign = FALSE)
index.open <- na.omit(data.frame(index3[, 1]))
index.close <- na.omit(data.frame(index3[, 4]))
index.open.test <- data.frame(index.open[1:(nrow(index.open) - 365), ])
# Discussion Figure 2 - Pressure audiograms for Elasmobranchs
setwd("H:/1. Shark Project/9. Data analysis/Behavioral Audiogram Analysis")
#getwd()
library(ggplot2)
library(ggpubr)
library(magrittr)
d <- read.table("Elasmo_audiogramms.txt",header=T,na.strings=c("NA","NaN",""),sep="\t")
FBlikeNumber <-
function(url) {
require(magrittr)
require(rvest)
x <- read_html(url, encoding = "UTF-8") %>% as.character
re <- regexpr("[,0-9]+(?= 人說這讚)", x, perl = T)
substr(x, re, re + attr(re, "match.length")) %>%
gsub(",", "", .) %>%
as.integer
}