이경수 선생님의 수학실험실

R의 데이터 타입_이름 속성 (Names Attribute) 본문

R

R의 데이터 타입_이름 속성 (Names Attribute)

(이경수) 2021. 4. 14. 22:49

R의 object들은 이름을 가질 수 있다.

> x<-1:3
> names(x)
NULL
> names(x)<-c("red","blue","green")
> x
  red  blue green 
    1     2     3 
> names(x)
[1] "red"   "blue"  "green"

 

리스트도 가능하다.

> x<-list(a=1,b=2,c=3)
> x
$a
[1] 1

$b
[1] 2

$c
[1] 3

 

행렬의 행이름과 열이름을 다음과 같은 방법으로 부여할 수 있다.

> m<-matrix(1:6,nrow=2,ncol=3)
> dimnames(m)<-list(c("F","M"),c("red","blue","green"))
> m
  red blue green
F   1    3     5
M   2    4     6

'R' 카테고리의 다른 글

Subsetting_Matrices  (0) 2021.04.15
Subsetting_Lists  (0) 2021.04.15
R의 데이터 타입_프레임(Frames)  (0) 2021.04.14
R의 데이터 타입_결측값(Missing Values)  (0) 2021.04.14
R의 데이터 타입_요인(Factors)  (0) 2021.04.14
Comments