R는 변수를 어떻게 구분하나요?

R에서 S3와 R6로 배우는 Object-Oriented Programming

Richie Cotton

Data Evangelist at DataCamp

str()

str(sleep)
'data.frame':    20 obs. of  3 variables:
 $ extra: num  0.7 -1.6 -0.2 -1.2 -0.1 ...
 $ group: Factor w/ 2 levels "1","2": 1 1 1 1 1 ...
 $ ID   : Factor w/ 10 levels "1","2","3","4",..: 1 2..
class(sleep)
"data.frame"
R에서 S3와 R6로 배우는 Object-Oriented Programming

int_mat

(int_mat <- matrix(1:12, 3))
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
class(int_mat)
"matrix"
typeof(int_mat)
"integer"
R에서 S3와 R6로 배우는 Object-Oriented Programming

num_mat

(num_mat <- matrix(rnorm(12), 3))
           [,1]       [,2]        [,3]       [,4]
[1,] -0.2911535 -0.1139933 -0.71290868  0.8640191
[2,] -2.2266419 -1.3604316 -1.90716974  0.4012884
[3,] -0.7504663 -1.2478873  0.01104117 -0.8127333
class(num_mat)
"matrix"
typeof(num_mat)
"double"
R에서 S3와 R6로 배우는 Object-Oriented Programming

 

 

 

mode()

storage.mode()

R에서 S3와 R6로 배우는 Object-Oriented Programming

요약

  • class()는 변수의 종류를 확인하는 데 첫 선택지입니다
  • typeof()가끔 유용합니다
  • mode()storage.mode()는 오래된 함수이니 사용하지 마세요
R에서 S3와 R6로 배우는 Object-Oriented Programming

연습해 봅시다!

R에서 S3와 R6로 배우는 Object-Oriented Programming

Preparing Video For Download...