データベースを読み込む
library(readxl)
dfInjury <- read_excel("kentei4.xlsx", sheet = "p55")
列の合計値を求める
sum(dfInjury$Pupils)
## [1] 40
相対度数を求める。Rでは列/列で求められる。
dfInjury$Proportion <- dfInjury$Pupils / sum(dfInjury$Pupils)
dfInjury$Proportion
## [1] 0.125 0.225 0.075 0.075 0.300 0.125 0.075
相対度数を求める関数:proportions
dfInjury$Proportion <- proportions(dfInjury$Pupils)
dfInjury
## # A tibble: 7 × 3
## Reason Pupils Proportion
## <chr> <dbl> <dbl>
## 1 切り傷 5 0.125
## 2 すり傷 9 0.225
## 3 ねんざ 3 0.075
## 4 発熱 3 0.075
## 5 頭痛 12 0.3
## 6 腹痛 5 0.125
## 7 その他 3 0.075