型は何でしょう?
この演習はコースの一部です
R における S3 と R6 を使ったオブジェクト指向プログラミング
演習の手順
ワークスペースには、入力に対する class()、mode()、typeof()、storage.mode() を返す type_info() 関数があらかじめ定義されています。(コンソールで type_info と入力して、どのように動くか確認できます。)
- エディタに用意されたサンプルオブジェクトを使って、
some_varsというリストを作成してください。 lapplyを使ってsome_varsの各要素をループし、各サンプルオブジェクトに対してtype_info()を呼び出して型を調べましょう。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Look at the definition of type_info()
type_info
# Create list of example variables
some_vars <- list(
an_integer_vector = rpois(24, lambda = 5),
a_numeric_vector = rbeta(24, shape1 = 1, shape2 = 1),
an_integer_array = array(rbinom(24, size = 8, prob = 0.5), dim = c(2, 3, 4)),
a_numeric_array = array(rweibull(24, shape = 1, scale = 1), dim = c(2, 3, 4)),
a_data_frame = data.frame(int = rgeom(24, prob = 0.5), num = runif(24)),
a_factor = factor(month.abb),
a_formula = y ~ x,
a_closure_function = mean,
a_builtin_function = length,
a_special_function = `if`
)
# Loop over some_vars calling type_info() on each element to explore them
___