tidyverseパッケージの機能
4108 ワード
レッスン:datacamp,Introduction to the Tidyversehttps://campus.datacamp.com/courses/introduction-to-the-tidyverse/grouping-and-summarizing?ex=6
dplyr変数名を羅列する. 使用:コロンは連続する変数名を表す. は、いくつかの変数を除外するためにマイナス記号を使用します. starts_を使用with(「文字列」)、ends_with(「文字列」)やcontains(「文字列」)などの関数.
順序の問題:
distinct
count
recode
データ型によって欠落値の書き方が異なります.
Remember that when recoding numeric variables, you need to put the old value in backticks, for example,
ggplot2データセット Second parameter is the mapping of variables in your dataset to aesthetics in your graph.データセット変数からグラフィック美観へのマッピングをマッピングします.・x軸・y軸・color・size レイヤー グラフィック
関数#カンスウ#
変数の数
シーンの適用
コメント
scatter plot
2つの連続変数
関係の傾向を呈する.
line plot
2変数、x-time,y-focus var
時間とともに変化する傾向を呈する
bar plot
2変数、x分類変数、y連続変数
2つの変数のクロス解析結果を表示
col is short for column. bar plotの縦軸は一般的に0から始まり、
histogram
1個の連続変数
単一変数データの分布
マッピングaesにはxしかありません.
box plot
2つの変数、x分類変数、y連続変数が可能
xの分類に従ってyの分布を比較する(histogramより優れている場所) log scale・ 分面・ 座標軸の開始位置・ を設定する.図面にタイトル・ を追加する.
dplyr
%>%
パイプ関数filter( )
フィルタcasesselect( )
フィルタ変数かっこ内で次のことができます.順序の問題:
ratings %>%
select(channel, everything(), -ends_with("day"))
everything()
is a great little helper! If it had been placed at the end, it would have added back in all the columns that end with “day”. Placing it before deselecting columns. arrange
変数の正または逆の順序に従ってdataset全体を並べ替えるarrange( )
正序arrange(desc( ))
逆順mutate( )
元の変数を修正したり、新しい変数を計算したりするsummarize( )
統計分析group_by( )
分類統計は、1つ以上の変数であってもよいgapminder %>%
group_by(year) %>%
summarize(medianLifeExp = median(lifeExp),
maxGdpPercap = max(gdpPercap))
distinct
# bakeoff result
bakeoff %>%
distinct(result)
count
#
bakeoff %>%
count(result)
> bakeoff %>%
count(result == "SB")
# A tibble: 2 x 2
`result == "SB"` n
1 FALSE 488
2 TRUE 61
# count
bakeoff %>%
count(series, episode) %>%
count(series)
bakers_by_series %>%
count(baker, sort = TRUE)
# , n
recode
recode
MSの「検索-置換」機能とmutate関数を組み合わせて新しい変数を生成したり、元の変数に基づいて置換したりすることができます.recode(.x, ..., .default = NULL, .missing = NULL)
desserts %>%
mutate(nut = recode(nut, "filbert" = "hazelnut"))
.x
処理したいベクトル...
はルールを置き換え、old values=new values .default
はspssの中のELSEに類似しており、設定してもしなくてもよい.設定すると.missing
はspssの中のMISSINGに似ていますデータ型によって欠落値の書き方が異なります.
NA_character_
for missing value for a character variable, NA_integer_
for missing integer data NA
value is of the logical type. Remember that when recoding numeric variables, you need to put the old value in backticks, for example,
5
= 6. ONLY old value! numericは数字に``backticks(反引用符)記号を付けます.例:`0` = NA_character_
# numeric character 。 0 NA 。
ggplot2
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp, color = continent, size = pop))+
geom_point()+
scale_x_log10()+
facet_wrap(~ year) +
expand_limits(y = 0)
ggplot( , ) +
関数#カンスウ#
変数の数
シーンの適用
コメント
scatter plot
geom_point()
2つの連続変数
関係の傾向を呈する.
line plot
geom_line()
2変数、x-time,y-focus var
時間とともに変化する傾向を呈する
bar plot
geom_col()
2変数、x分類変数、y連続変数
2つの変数のクロス解析結果を表示
col is short for column. bar plotの縦軸は一般的に0から始まり、
expand_limits(y = 0)
を設けない.histogram
geom_histogram()
1個の連続変数
単一変数データの分布
マッピングaesにはxしかありません.
geom_histogram(bins = 5)
binsはグループピッチを設定します.box plot
geom_boxplot()
2つの変数、x分類変数、y連続変数が可能
xの分類に従ってyの分布を比較する(histogramより優れている場所)
scale_x_log10()
x軸のスケールをlog 10単位に変更します.facet_wrap(~ )
expand_limits(y = 0)
labs(title = "Comparing GDP per capita across continents")
・ggtitle("Comparing GDP per capita across continents")