R names()

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 00:42 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>))

1 개요

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

2 예제 1

<source lang='r'> z <- 1:5 z

    1. [1] 1 2 3 4 5

names(z) <- letters[1:5] z

    1. a b c d e
    2. 1 2 3 4 5

names(z[3])

    1. [1] "c"

names(z[3:5])

    1. [1] "c" "d" "e"

names(z[c(3,5)])

    1. [1] "c" "e"

</syntaxhighlight> <source lang='r'> z <- 1:5 class(z)

    1. [1] "integer"

str(z)

    1. int [1:5] 1 2 3 4 5

names(z) <- letters[1:5] class(z)

    1. [1] "integer"

str(z)

    1. Named int [1:5] 1 2 3 4 5
    2. - attr(*, "names")= chr [1:5] "a" "b" "c" "d" ...

names(z) <- NULL class(z)

    1. [1] "integer"

str(z)

    1. int [1:5] 1 2 3 4 5

</syntaxhighlight>

3 예제 2

<source lang='r'> z <- letters[1:5] z

    1. [1] "a" "b" "c" "d" "e"

names(z) <- 1:5 z

    1. 1 2 3 4 5
    2. "a" "b" "c" "d" "e"

names(z) <- NULL z [1] "a" "b" "c" "d" "e"

    1. [1] "a" "b" "c" "d" "e"

</syntaxhighlight> <source lang='r'> z <- letters[1:5] class(z)

    1. [1] "character"

str(z)

    1. chr [1:5] "a" "b" "c" "d" "e"

names(z) <- 1:5 class(z)

    1. [1] "character"

str(z)

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

names(z) <- NULL class(z)

    1. [1] "character"

str(z)

    1. chr [1:5] "a" "b" "c" "d" "e"

</syntaxhighlight>

4 예제 3

<source lang='r'> str(islands)

    1. Named num [1:48] 11506 5500 16988 2968 16 ...
    2. - attr(*, "names")= chr [1:48] "Africa" "Antarctica" "Asia" "Australia" ...

names(islands)

    1. [1] "Africa" "Antarctica" "Asia" "Australia"
    2. [5] "Axel Heiberg" "Baffin" "Banks" "Borneo"
    3. [9] "Britain" "Celebes" "Celon" "Cuba"
    4. [13] "Devon" "Ellesmere" "Europe" "Greenland"
    5. [17] "Hainan" "Hispaniola" "Hokkaido" "Honshu"
    6. [21] "Iceland" "Ireland" "Java" "Kyushu"
    7. [25] "Luzon" "Madagascar" "Melville" "Mindanao"
    8. [29] "Moluccas" "New Britain" "New Guinea" "New Zealand (N)"
    9. [33] "New Zealand (S)" "Newfoundland" "North America" "Novaya Zemlya"
    10. [37] "Prince of Wales" "Sakhalin" "South America" "Southampton"
    11. [41] "Spitsbergen" "Sumatra" "Taiwan" "Tasmania"
    12. [45] "Tierra del Fuego" "Timor" "Vancouver" "Victoria"

</syntaxhighlight>

5 예제 4

<source lang='r'> z <- list(a = 1, b = "c", c = 1:3) z

    1. $a
    2. [1] 1
    3. $b
    4. [1] "c"
    5. $c
    6. [1] 1 2 3

names(z)

    1. [1] "a" "b" "c"

names(z[3])

    1. [1] "c"

</syntaxhighlight>

6 같이 보기

7 참고

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