LoginSignup
3
1

More than 3 years have passed since last update.

[R]基本統計量の算出

Last updated at Posted at 2018-12-25

データセットの準備

data = c(12, 3 ,5, 2, 6, 7, 9, 6, 4, 11)

summaryを使ってざっくりと出してみる

summary(data)
>  Min. 1st Qu.  Median    Mean   3rd Qu.  Max. 
   2.00    4.25    6.00    6.50    8.50   12.00 

自分の中でざっくりと見るのに楽な方法の一つ

summary()関数の戻り値の意味

summary() 意味
Min 最小値
1st Qu 第一四分位数
Median 中央値
Mean 平均値
3rd Qu 第三四分位数
Max 最大値

平均値

mean(data)
> 6.5

中央値

median(data)
> 6

最頻値

Rでは最頻値を一発で算出するものはなさそうなので、table関数を使って算出したいと思います。
まずは単純にtable関数だけを使うとこんな感じ

table(data)
>data
 2  3  4  5  6  7  9 11 12 
 1  1  1  1  2  1  1  1  1 

上がデータの値。下がその頻度を表しています。この程度のサンプルサイズであれば問題ないですが、大きくなると困るので最頻値を目視でなくて、きちんと算出してみましょう

x <- table(data)
x[x == max(x)]
>6 
 2 

不偏分散

var(data)
> 10.94444

不偏標準偏差

sd(data)
>3.308239
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1