Skip to content

Instantly share code, notes, and snippets.

@fufufukakaka
Created May 13, 2017 09:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fufufukakaka/5df97cb19c93a2f2cc28bfc2e25162a9 to your computer and use it in GitHub Desktop.
Save fufufukakaka/5df97cb19c93a2f2cc28bfc2e25162a9 to your computer and use it in GitHub Desktop.
Lab-on article "Transition from Excel to R" Appendix
---
title: "pokemontest"
output: html_document
---
## 列数
```{r}
#データの読み込み
df<-read.csv('../dataset/pokemon.csv',encoding = 'utf-8',sep='\t')
#列数の取得
nrow(df)
```
## 平均の計算
```{r}
#データの読み込み
df<-read.csv('../dataset/pokemon.csv',encoding = 'utf-8',sep='\t')
#平均を計算
colMeans(df[,c(5,6,7,8,9,10,11)])
```
## 要約統計量の計算
```{r}
#データの読み込み
df<-read.csv('../dataset/pokemon.csv',encoding = 'utf-8',sep='\t')
#要約統計量の計算
summary(df[,c(5,6,7,8,9,10,11)])
```
## 種族値合計のヒストグラム
```{r}
#データの読み込み
df<-read.csv('../dataset/pokemon.csv',encoding = 'utf-8',sep='\t')
#文字化け対策
par(family = "HiraKakuProN-W3")
#ヒストグラムの出力
hist(df$種族値合計)
```
## 世代と種族値合計の関係性
```{r}
#データの読み込み
df<-read.csv('../dataset/pokemon.csv',encoding = 'utf-8',sep='\t')
#回帰分析
result<-lm(df$種族値合計~df$世代)
#結果の取得
summary(result)
#グラフ描画用のパッケージの読み込み
require(ggplot2)
#散布図と回帰直線
g <- ggplot(
df, # ggplot 用データフレーム
aes (
x = df$世代, # x 軸に df$x を指定
y = df$種族値合計 # y 軸に df$y を指定
)
)
g <- g + geom_point(
shape = 20, # プロットのタイプを指定
size = 0.8, # プロットのサイズを指定
na.rm = TRUE # 非数値を無視
)
g <- g + geom_smooth(method = "lm" #近似線は回帰法によって求める
) + theme_bw(base_family = "HiraKakuProN-W3")
#描画
plot(g)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment