R names()

1 개요[ | ]

R names()
  • 객체에 대한 이름들을 얻거나(get) 설정하는(set) R 함수

2 예제 1[ | ]

z <- 1:5
z
## [1] 1 2 3 4 5

names(z) <- letters[1:5]
z
## a b c d e 
## 1 2 3 4 5
names(z[3])
## [1] "c"
names(z[3:5])
## [1] "c" "d" "e"
names(z[c(3,5)])
## [1] "c" "e"
z <- 1:5
class(z)
## [1] "integer"
str(z)
##  int [1:5] 1 2 3 4 5

names(z) <- letters[1:5]
class(z)
## [1] "integer"
str(z)
##  Named int [1:5] 1 2 3 4 5
##  - attr(*, "names")= chr [1:5] "a" "b" "c" "d" ...

names(z) <- NULL
class(z)
## [1] "integer"
str(z)
##  int [1:5] 1 2 3 4 5

3 예제 2[ | ]

z <- letters[1:5]
z
## [1] "a" "b" "c" "d" "e"

names(z) <- 1:5
z
##   1   2   3   4   5 
## "a" "b" "c" "d" "e" 

names(z) <- NULL
z
[1] "a" "b" "c" "d" "e"
## [1] "a" "b" "c" "d" "e"
z <- letters[1:5]
class(z)
## [1] "character"
str(z)
##  chr [1:5] "a" "b" "c" "d" "e"

names(z) <- 1:5
class(z)
## [1] "character"
str(z)
##  Named chr [1:5] "a" "b" "c" "d" "e"
##  - attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...

names(z) <- NULL
class(z)
## [1] "character"
str(z)
##  chr [1:5] "a" "b" "c" "d" "e"

4 예제 3[ | ]

str(islands)
names(islands)

5 예제 4[ | ]

z <- list(a = 1, b = "c", c = 1:3)
z
names(z)
names(z[3])

6 같이 보기[ | ]

7 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}