- A.super
- B.begin
- C.try
- D.goto
def foo (a, *b)
p a
| kawabata <- "国境の長いトンネルを抜けると雪国であった。夜の底が白くなった。信号所に汽車が止 | |
| まった。" | |
| kawabata.2 <- strsplit(kawabata, "") | |
| kawabata.3 <- table(kawabata.2) | |
| # 文字の頻度表 | |
| data.frame(kawabata.3) |
| ``` | |
| require(stats); require(graphics) | |
| par(mfrow = c(2, 2)) | |
| plot(Nile) | |
| acf(Nile) | |
| pacf(Nile) | |
| ar(Nile) # selects order 2 | |
| cpgram(ar(Nile)$resid) | |
| par(mfrow = c(1, 1)) | |
| arima(Nile, c(2, 0, 0)) |
| ``` | |
| # 行列を作成 | |
| matrix(c(1, 2, 3, 4), nrow = 2) # 引数nrowで行列の行数を指定 | |
| matrix(c(1, 2, 3, 4), nrow = 2, byrow = TRUE) # 引数byrowでTRUEを指定すると、数字の配置が換わる(要注意) | |
| # 変数に行列を代入 | |
| m1 <- matrix(c(12, 17, 22, 16), nrow = 2) | |
| # 代入結果を確認 | |
| m1 | |
| # 行列の行数や列数を確認 | |
| nrow(m1) |
| library(tidyverse) # data manipulation and visualization | |
| library(gapminder) # data | |
| library(countrycode) # visualization | |
| library(highcharter) # visualization | |
| foo <- gapminder %>% | |
| + filter(year == 2007) %>% | |
| + mutate(iso3 = countrycode(country, origin = "country.name", destination = "iso3c")) | |
| highchart() %>% | |
| + hc_add_series_map(worldgeojson, foo, value = 'lifeExp', joinBy = 'iso3') %>% | |
| + hc_title(text = 'Life expectancy in 2007') %>% |
#第5章 #zipf法則のグラフ
ABE<-read.csv("http://mjin.doshisha.ac.jp/iwanami/data/ABE.csv",head=T,row.names=1)
FUKUDA<-read.csv("http://mjin.doshisha.ac.jp/iwanami/data/FUKUDA.csv",head=T,row.names=1)
par(mfrow=c(1,2),mar=c(4.5,4,1,1))
plot(1:nrow(FUKUDA),FUKUDA[,1],xlab="ランク",ylab="頻度")
plot(log(1:nrow(FUKUDA)),log(FUKUDA[,1]),xlab="ランクの対数",ylab="頻度の対数")
lm(log(FUKUDA[,1])~log(1:nrow(FUKUDA)))->fukuda.lm
abline(fukuda.lm,lw=2)
########## 第1章 ##########
# 1から4までの数値をxという変数に代入(c関数を使用)
x <- c(1, 2, 3, 4)
# sum関数を使って,変数xの中の数値の総和を計算
sum(x)
| # 『Rで楽しむ統計』全コード | |
| ## 第1章 Rで遊ぶ | |
| ### 1.1 Rとは | |
| ### 1.2 簡単な計算 | |
| ``` | |
| > 123 + 456 |
| # 分析データ | |
| library(languageR) | |
| data(alice) | |
| # 全ての文字を小文字に変換 | |
| alice.lower <- tolower(alice) | |
| # ワードリストの作成 | |
| freq.list <- table(alice.lower) | |
| sorted.freq.list <- sort(freq.list, decreasing = TRUE) | |
| sorted.table <- paste(names(sorted.freq.list), sorted.freq.list, sep = ": ") |