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
| # 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") |
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
| 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 | |
| } |
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
| TEST_GUI = function() { | |
| library(tcltk2) | |
| win1 <- tktoplevel() | |
| win1$env$rb1 <- tk2radiobutton(win1) | |
| win1$env$rb2 <- tk2radiobutton(win1) | |
| win1$env$rb3 <- tk2radiobutton(win1) | |
| rbValue <- tclVar("PANDA") | |
| tkconfigure(win1$env$rb1, variable = rbValue, value = 1) | |
| tkconfigure(win1$env$rb2, variable = rbValue, value = 2) |
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
| # see https://www.ptt.cc/bbs/R_Language/M.1540859231.A.848.html | |
| theta <- 8 # 本例以 theta = 8 為例 | |
| n.delta <- 500 # 設定方格在 x 和 y 的格數 | |
| x.sim <- seq(-theta, theta, length = n.delta) | |
| y.sim <- seq(-14, 14, length = n.delta) # 太窄或太寬可以調整 | |
| f.xy <- | |
| function(x, y, th) { | |
| 1 / (2 * th * sqrt(2 * pi)) * exp(-1 / 2 * (y - x) ^ 2) | |
| } |
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(data.table) | |
| library(ggplot2) | |
| library(magrittr) | |
| # raw data | |
| set.seed(123) | |
| d <- | |
| data.table( | |
| Week = gl(2, 12, labels = c("48", "49")), | |
| Factory = gl(3, 4, labels = c("Factory1", "Factory2", "Factory3")), |
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
| rm(dat) | |
| library(httr) | |
| library(xml2) | |
| library(RCurl) | |
| library(XML) | |
| library(dplyr) | |
| library(data.table) | |
| ## 抓八卦板的資料 |
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
| Browser | resolution | fps | seqnum | var | val | ||
|---|---|---|---|---|---|---|---|
| 1 | Firefox 43.0.4 | 0480p | 30fps | 2 | Total CPU usage (%) | 65.6 | |
| 2 | Firefox 43.0.4 | 0480p | 30fps | 3 | Total CPU usage (%) | 70.5 | |
| 3 | Firefox 43.0.4 | 0480p | 30fps | 4 | Total CPU usage (%) | 69.9 | |
| 4 | Firefox 43.0.4 | 0480p | 30fps | 5 | Total CPU usage (%) | 71 | |
| 5 | Firefox 43.0.4 | 0480p | 30fps | 6 | Total CPU usage (%) | 67.8 | |
| 6 | Firefox 43.0.4 | 0480p | 30fps | 7 | Total CPU usage (%) | 64.5 | |
| 7 | Firefox 43.0.4 | 0480p | 30fps | 8 | Total CPU usage (%) | 67.1 | |
| 8 | Firefox 43.0.4 | 0480p | 30fps | 9 | Total CPU usage (%) | 67.6 | |
| 9 | Firefox 43.0.4 | 0480p | 30fps | 10 | Total CPU usage (%) | 67.5 |
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
| # dat 為輸入的二因子資料 | |
| set.seed(1234) | |
| dat <- data.frame( | |
| y = rnorm(80, 5, 2), | |
| x1 = gl(2, 40, labels = c("A","B")), | |
| x2 = gl(4, 10, labels = c("1","2","3","4")) | |
| ) | |
| # 利用 tapply 求出各組之 mean 和 sd | |
| y.mean <- with(dat, tapply(y, paste(x1, x2, sep="."), mean)) |
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
| # 第一題 | |
| # 已知 x 如下 | |
| x <- c(23,52,63,2,34,6,45,67,73,24,63,75,35,23,7,45,7,34) | |
| # 以抽出且放回的方法隨機抽出 x 中的數, | |
| # 抽出的量和 x 一樣多(也就是 18 個)。 | |
| # 求出這 18 個數的平均。 | |
| # 把上述的過程重複 10000 次,並把每次的平均記錄在一個 vector 「假的平均」裡。 | |
| # 最後,試著看懂 ?quantile,求出「假的平均」的 2.5% 和 97.5% 分位數。 | |
| # 以下是提示,試著把 ??? 填上適當的 R code。 | |
| 重覆次數 <- 10000 |
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
| ## string to class Date | |
| dates <- c("01/27/92", "03/27/92") | |
| x <- as.Date(dates, "%m/%d/%y") # see ?strptime to learn more | |
| ## class Date to string | |
| format(x, "%x") | |
| format(x, "%F") | |
| format(x, "%c") | |
| format(x, "%b %D %Y") |