表示を科学表示から変更
options(scipen = 999)
# 変数の消去
rm(list = ls())
# 表示を科学表示から変更
options(scipen = 999)
# パッケージ `pacman`を使って必要なパッケージをインストール
if(!require("pacman")) install.packages("pacman")
## 要求されたパッケージ pacman をロード中です
pacman::p_load("tidyverse", "skimr")
# データサイエンスのための基本パッケージセット
# https://www.tidyverse.org/
library(tidyverse)
# readr, readxl, googlesheet 4は tidyverseに含まれる
# 読み込んだデータのまとめ
library(skimr)
getwd()
## [1] "C:/Users/coo/Desktop/date"
ls("package:datasets")
## [1] "ability.cov" "airmiles" "AirPassengers"
## [4] "airquality" "anscombe" "attenu"
## [7] "attitude" "austres" "beaver1"
## [10] "beaver2" "BJsales" "BJsales.lead"
## [13] "BOD" "cars" "ChickWeight"
## [16] "chickwts" "co2" "CO2"
## [19] "crimtab" "discoveries" "DNase"
## [22] "esoph" "euro" "euro.cross"
## [25] "eurodist" "EuStockMarkets" "faithful"
## [28] "fdeaths" "Formaldehyde" "freeny"
## [31] "freeny.x" "freeny.y" "HairEyeColor"
## [34] "Harman23.cor" "Harman74.cor" "Indometh"
## [37] "infert" "InsectSprays" "iris"
## [40] "iris3" "islands" "JohnsonJohnson"
## [43] "LakeHuron" "ldeaths" "lh"
## [46] "LifeCycleSavings" "Loblolly" "longley"
## [49] "lynx" "mdeaths" "morley"
## [52] "mtcars" "nhtemp" "Nile"
## [55] "nottem" "npk" "occupationalStatus"
## [58] "Orange" "OrchardSprays" "PlantGrowth"
## [61] "precip" "presidents" "pressure"
## [64] "Puromycin" "quakes" "randu"
## [67] "rivers" "rock" "Seatbelts"
## [70] "sleep" "stack.loss" "stack.x"
## [73] "stackloss" "state.abb" "state.area"
## [76] "state.center" "state.division" "state.name"
## [79] "state.region" "state.x77" "sunspot.month"
## [82] "sunspot.year" "sunspots" "swiss"
## [85] "Theoph" "Titanic" "ToothGrowth"
## [88] "treering" "trees" "UCBAdmissions"
## [91] "UKDriverDeaths" "UKgas" "USAccDeaths"
## [94] "USArrests" "UScitiesD" "USJudgeRatings"
## [97] "USPersonalExpenditure" "uspop" "VADeaths"
## [100] "volcano" "warpbreaks" "women"
## [103] "WorldPhones" "WWWusage"
cars_temp <- cars
iris_temp <- iris
str(cars_temp)
## 'data.frame': 50 obs. of 2 variables:
## $ speed: num 4 4 7 7 8 9 10 10 10 11 ...
## $ dist : num 2 10 4 22 16 10 18 26 34 17 ...
str(iris_temp)
## 'data.frame': 150 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
skimr::skim(cars_temp)
Data summary
| Name |
cars_temp |
| Number of rows |
50 |
| Number of columns |
2 |
| _______________________ |
|
| Column type frequency: |
|
| numeric |
2 |
| ________________________ |
|
| Group variables |
None |
Variable type: numeric
| speed |
0 |
1 |
15.40 |
5.29 |
4 |
12 |
15 |
19 |
25 |
▂▅▇▇▃ |
| dist |
0 |
1 |
42.98 |
25.77 |
2 |
26 |
36 |
56 |
120 |
▅▇▅▂▁ |
skimr::skim(iris_temp)
Data summary
| Name |
iris_temp |
| Number of rows |
150 |
| Number of columns |
5 |
| _______________________ |
|
| Column type frequency: |
|
| factor |
1 |
| numeric |
4 |
| ________________________ |
|
| Group variables |
None |
Variable type: factor
| Species |
0 |
1 |
FALSE |
3 |
set: 50, ver: 50, vir: 50 |
Variable type: numeric
| Sepal.Length |
0 |
1 |
5.84 |
0.83 |
4.3 |
5.1 |
5.80 |
6.4 |
7.9 |
▆▇▇▅▂ |
| Sepal.Width |
0 |
1 |
3.06 |
0.44 |
2.0 |
2.8 |
3.00 |
3.3 |
4.4 |
▁▆▇▂▁ |
| Petal.Length |
0 |
1 |
3.76 |
1.77 |
1.0 |
1.6 |
4.35 |
5.1 |
6.9 |
▇▁▆▇▂ |
| Petal.Width |
0 |
1 |
1.20 |
0.76 |
0.1 |
0.3 |
1.30 |
1.8 |
2.5 |
▇▁▇▅▃ |
library(gt)
cars_temp |> head(n = 10) |>gt()
| speed |
dist |
| 4 |
2 |
| 4 |
10 |
| 7 |
4 |
| 7 |
22 |
| 8 |
16 |
| 9 |
10 |
| 10 |
18 |
| 10 |
26 |
| 10 |
34 |
| 11 |
17 |
iris_temp |> tail(n = 10) |> gt() |>
tab_header(
title = "アヤメデータ",
subtitle = "rに入っているデータの一つです") |>
cols_label(
Sepal.Length = "がく片の長さ",
Sepal.Width = "がく片の幅" )
| アヤメデータ |
| rに入っているデータの一つです |
| がく片の長さ |
がく片の幅 |
Petal.Length |
Petal.Width |
Species |
| 6.7 |
3.1 |
5.6 |
2.4 |
virginica |
| 6.9 |
3.1 |
5.1 |
2.3 |
virginica |
| 5.8 |
2.7 |
5.1 |
1.9 |
virginica |
| 6.8 |
3.2 |
5.9 |
2.3 |
virginica |
| 6.7 |
3.3 |
5.7 |
2.5 |
virginica |
| 6.7 |
3.0 |
5.2 |
2.3 |
virginica |
| 6.3 |
2.5 |
5.0 |
1.9 |
virginica |
| 6.5 |
3.0 |
5.2 |
2.0 |
virginica |
| 6.2 |
3.4 |
5.4 |
2.3 |
virginica |
| 5.9 |
3.0 |
5.1 |
1.8 |
virginica |