반응형
List 를 이용한 방법
# dictionary 생성
dict <- list(name = "John", age = 30, city = "New York")
# dictionary 사용
dict$name
# [1] "John"
dict$age
# [1] 30
dict$city
# [1] "New York"
vector 를 활용한 방법
ㄴ setNames 함수를 활용
# dictionary 생성
dict <- setNames(c("John", 30, "New York"), c("name", "age", "city"))
# dictionary 사용
dict$name
# [1] "John"
dict$age
# [1] 30
dict$city
# [1] "New York"
hash 함수를 활용한 방법
library(hash)
h <- hash()
h[['a']] <- 'a'
h[['b']] <- 'b'
h[['c']] <- 'c'
h[['d']] <- 'd'
h[['a']]
반응형
'Tools > R' 카테고리의 다른 글
R 에서 폰트 사용하는 방법 (linux) (0) | 2024.04.04 |
---|---|
R - 리스트 문자열을 벡터로 바꾸고 unnest 하기 (0) | 2024.03.06 |
R - 변수 bucketing (카테고리화) (0) | 2023.03.10 |
R - lag 변수 만들기 (0) | 2023.03.10 |
R - 반복문 대신 사용하는 lapply 패턴 (0) | 2023.03.10 |