"R names()"의 두 판 사이의 차이

잔글 (봇: Jmnote의 2020-10-25T09:17:10Z 에 작성한 602488 판으로 되돌림)
잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
4번째 줄: 4번째 줄:


==예제 1==
==예제 1==
<source lang='r'>
<syntaxhighlight lang='r'>
z <- 1:5
z <- 1:5
z
z
19번째 줄: 19번째 줄:
names(z[c(3,5)])
names(z[c(3,5)])
## [1] "c" "e"
## [1] "c" "e"
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
z <- 1:5
z <- 1:5
class(z)
class(z)
39번째 줄: 39번째 줄:
str(z)
str(z)
##  int [1:5] 1 2 3 4 5
##  int [1:5] 1 2 3 4 5
</source>
</syntaxhighlight>


==예제 2==
==예제 2==
<source lang='r'>
<syntaxhighlight lang='r'>
z <- letters[1:5]
z <- letters[1:5]
z
z
56번째 줄: 56번째 줄:
[1] "a" "b" "c" "d" "e"
[1] "a" "b" "c" "d" "e"
## [1] "a" "b" "c" "d" "e"
## [1] "a" "b" "c" "d" "e"
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
z <- letters[1:5]
z <- letters[1:5]
class(z)
class(z)
76번째 줄: 76번째 줄:
str(z)
str(z)
##  chr [1:5] "a" "b" "c" "d" "e"
##  chr [1:5] "a" "b" "c" "d" "e"
</source>
</syntaxhighlight>


==예제 3==
==예제 3==
<source lang='r'>
<syntaxhighlight lang='r'>
str(islands)
str(islands)
##  Named num [1:48] 11506 5500 16988 2968 16 ...
##  Named num [1:48] 11506 5500 16988 2968 16 ...
96번째 줄: 96번째 줄:
## [41] "Spitsbergen"      "Sumatra"          "Taiwan"          "Tasmania"         
## [41] "Spitsbergen"      "Sumatra"          "Taiwan"          "Tasmania"         
## [45] "Tierra del Fuego" "Timor"            "Vancouver"        "Victoria"     
## [45] "Tierra del Fuego" "Timor"            "Vancouver"        "Victoria"     
</source>
</syntaxhighlight>


==예제 4==
==예제 4==
<source lang='r'>
<syntaxhighlight lang='r'>
z <- list(a = 1, b = "c", c = 1:3)
z <- list(a = 1, b = "c", c = 1:3)
z
z
114번째 줄: 114번째 줄:
names(z[3])
names(z[3])
## [1] "c"
## [1] "c"
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 00:56 판

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)
##  Named num [1:48] 11506 5500 16988 2968 16 ...
##  - attr(*, "names")= chr [1:48] "Africa" "Antarctica" "Asia" "Australia" ...
names(islands)
##  [1] "Africa"           "Antarctica"       "Asia"             "Australia"       
##  [5] "Axel Heiberg"     "Baffin"           "Banks"            "Borneo"          
##  [9] "Britain"          "Celebes"          "Celon"            "Cuba"            
## [13] "Devon"            "Ellesmere"        "Europe"           "Greenland"       
## [17] "Hainan"           "Hispaniola"       "Hokkaido"         "Honshu"          
## [21] "Iceland"          "Ireland"          "Java"             "Kyushu"          
## [25] "Luzon"            "Madagascar"       "Melville"         "Mindanao"        
## [29] "Moluccas"         "New Britain"      "New Guinea"       "New Zealand (N)" 
## [33] "New Zealand (S)"  "Newfoundland"     "North America"    "Novaya Zemlya"   
## [37] "Prince of Wales"  "Sakhalin"         "South America"    "Southampton"     
## [41] "Spitsbergen"      "Sumatra"          "Taiwan"           "Tasmania"        
## [45] "Tierra del Fuego" "Timor"            "Vancouver"        "Victoria"

5 예제 4

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

6 같이 보기

7 참고

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