내 타입은 무엇일까요?
이 연습은 강의의 일부입니다
R에서 S3와 R6로 배우는 Object-Oriented Programming
연습 안내
type_info() 함수가 워크스페이스에 미리 정의되어 있어서 입력값의 class(), mode(), typeof(), storage.mode()를 반환합니다. (작동 방식을 보려면 콘솔에 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
___