- R 的簡介
- R 的傳統用途
- R 的社群與近代R 的演變
- 如何學習R 語言
Wush Wu
國立台灣大學
plot(density(x))
shaprio.test(x)
Shapiro-Wilk normality test
data: x
W = 0.9291, p-value = 4.427e-05
plot(density(x1), xlim = range(c(x1, x2)), main = "Sample PDF")
lines(density(x2), col = 2)
legend("topright", c("x1", "x2"), lty = 1, col = 1:2)
ks.test(x1, x2)
Two-sample Kolmogorov-Smirnov test
data: x1 and x2
D = 0.14, p-value = 0.7166
alternative hypothesis: two-sided
suppressPackageStartupMessages(library(PerformanceAnalytics))
chart.Correlation(iris[-5], bg=iris$Species, pch=21)
1,234
-99
來代表資料的遺失2015-12-21 08:48:44 INFO::Crawling page from 2013-10/00105-page.csv.gz
2015-12-21 08:48:44 INFO::Crawling (1/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (2/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (3/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (4/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (5/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (6/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (7/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (8/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (9/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (10/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (11/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (12/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (13/100 2013-10:2013-10/00105-page.csv.gz)
2015-12-21 08:48:44 INFO::Crawling (14/100 2013-10:2013-10/00105-page.csv.gz)
library(quantmod)
getSymbols("^TWII")
head(TWII)
TWII.Open | TWII.High | TWII.Low | TWII.Close | TWII.Volume | TWII.Adjusted |
---|---|---|---|---|---|
7871.41 | 7937.26 | 7843.60 | 7920.80 | 5710600 | 7920.80 |
7954.96 | 7999.42 | 7917.30 | 7917.30 | 5951400 | 7917.30 |
7929.89 | 7955.90 | 7901.24 | 7934.51 | 5717400 | 7934.51 |
7940.20 | 7942.23 | 7821.71 | 7835.57 | 5181400 | 7835.57 |
7778.57 | 7797.57 | 7736.11 | 7736.71 | 4292400 | 7736.71 |
7778.38 | 7827.93 | 7778.38 | 7790.01 | 4516000 | 7790.01 |
chartSeries(TWII, subset = "last 4 months", TA = c(addVo(), addBBands()))
library(Lahman)
head(Teams[,c("yearID", "name", "Rank", "W", "L", "R", "RA")])
yearID | name | Rank | W | L | R | RA |
---|---|---|---|---|---|---|
1871 | Boston Red Stockings | 3 | 20 | 10 | 401 | 303 |
1871 | Chicago White Stockings | 2 | 19 | 9 | 302 | 241 |
1871 | Cleveland Forest Citys | 8 | 10 | 19 | 249 | 341 |
1871 | Fort Wayne Kekiongas | 7 | 7 | 12 | 137 | 243 |
1871 | New York Mutuals | 5 | 16 | 17 | 302 | 313 |
1871 | Philadelphia Athletics | 1 | 21 | 7 | 376 | 266 |
playerID | yearID | W | L | ERA |
---|---|---|---|---|
wangch01 | 2005 | 8 | 5 | 4.02 |
wangch01 | 2006 | 19 | 6 | 3.63 |
wangch01 | 2007 | 19 | 7 | 3.70 |
wangch01 | 2008 | 8 | 2 | 4.07 |
wangch01 | 2009 | 1 | 6 | 9.64 |
wangch01 | 2011 | 4 | 3 | 4.04 |
Call:
lm(formula = dist ~ speed, data = cars)
Residuals:
Min 1Q Median 3Q Max
-29.069 -9.525 -2.272 9.215 43.201
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -17.5791 6.7584 -2.601 0.0123 *
speed 3.9324 0.4155 9.464 1.49e-12 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 15.38 on 48 degrees of freedom
Multiple R-squared: 0.6511, Adjusted R-squared: 0.6438
F-statistic: 89.57 on 1 and 48 DF, p-value: 1.49e-12
library(sjPlot)
sjt.lm(lm(dist ~ speed, cars))
dist | ||||
B | CI | p | ||
(Intercept) | -17.58 | -31.17 – -3.99 | .012 | |
speed | 3.93 | 3.10 – 4.77 | <.001 | |
Observations | 50 | |||
R2 / adj. R2 | .651 / .644 |
gsub
、regmatch
、substring
、paste
...as.numeric
...cut
、factor
...split
...stringr
、stringi
lubridate
dplyr
: 以類SQL 的方式讓我們有系統化的手法處理資料(表)
%>%
程式諮詢
(做21點的遊戲)
[問題敘述]:
電腦對電腦玩,目前卡在
sample(52)
cards<-sample(52)
num<-cards%%13
get_num = function(cards){
factor(cards %% 13, levels = 0:12, labels = c(1:10, "J", "Q", "K"))
}
get_suit = function(cards){
factor((cards-1) %/% 13, levels = 0:3,
labels = c("spade", "heart", "diamend","club"))
}
desk = sample(1:52)
n_player = 2
num_cards_out = 0
player_cards = vector('list', n_player)
同學作業要自己做喔
老師會不定期來查水表
誰作業跟這篇一樣就GG了
希望這學期不用動用程式碼比對工具
P.S. 老師已備份這篇
[Rd] R 3.3 on March 6
Peter Dalgaard pd.mes at cbs.dk
Sun Feb 5 15:14:41 CET 2017
...
The wrap-up release of the R-3.3.x series will be on Monday, March 6th.
Package maintainers should check that their packages still work with this release. In particular, recommended-package maintainers should be extra careful since we do not want unexpected turbulence at this point.
On behalf of the R Core Team
Peter Dalgaard
...
出處: https://stat.ethz.ch/pipermail/r-devel/2017-February/073705.html