R 기초; 리스트 인덱싱-2
product <- list(id="A001", name="Mouse", price=30000)
product
$id
[1] "A001"
$name
[1] "Mouse"
$price
[1] 30000
product[[3]] <- 40000
product[["price"]] <- 40000
product$price <- 40000
product
$id
[1] "A001"
$name
[1] "Mouse"
$price
[1] 40000
product[3] <- 40000
product["price"] <- 40000
product
$id
[1] "A001"
$name
[1] "Mouse"
$price
[1] 40000
product[[3]] <- c(30000, 40000)
product[3] <- list(c(30000, 40000))
product
$id
[1] "A001"
$name
[1] "Mouse"
$price
[1] 30000 40000
product[1:3] <- list("A002", "Keyboard", 90000)
product
$id
[1] "A002"
$name
[1] "Keyboard"
$price
[1] 90000
product[[4]] <- c("Domestic", "Export")
product
$id
[1] "A002"
$name
[1] "Keyboard"
$price
[1] 90000
[[4]]
[1] "Domestic" "Export"
product$madein <- c("Korea", "China")
product[["madein"]] <- c("Korea", "China")
product
$id
[1] "A002"
$name
[1] "Keyboard"
$price
[1] 90000
[[4]]
[1] "Domestic" "Export"
$madein
[1] "Korea" "China"
product[6:9] <- list(0.12, 0.15, 0.22, 0.27)
product
$id
[1] "A002"
$name
[1] "Keyboard"
$price
[1] 90000
[[4]]
[1] "Domestic" "Export"
$madein
[1] "Korea" "China"
[[6]]
[1] 0.12
[[7]]
[1] 0.15
[[8]]
[1] 0.22
[[9]]
[1] 0.27
names <- c("Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun")
values <- c(842, 729, 786, 751, 844, 851, 702)
traffic.death <- list()
traffic.death[names] <- values
traffic.death
$Mon
[1] 842
$Tue
[1] 729
$Wed
[1] 786
$Thur
[1] 751
$Fri
[1] 844
$Sat
[1] 851
$Sun
[1] 702
traffic.death[["Fri"]] <- NULL
traffic.death
$Mon
[1] 842
$Tue
[1] 729
$Wed
[1] 786
$Thur
[1] 751
$Sat
[1] 851
$Sun
[1] 702
traffic.death[c("Sat", "Sun")] <- NULL
traffic.death
$Mon
[1] 842
$Tue
[1] 729
$Wed
[1] 786
$Thur
[1] 751
traffic.death < 750
Mon Tue Wed Thur
FALSE TRUE FALSE FALSE
traffic.death[traffic.death < 750] <- NULL
traffic.death
$Mon
[1] 842
$Wed
[1] 786
$Thur
[1] 751
'공부 > R Programming' 카테고리의 다른 글
R 기초; 데이터프레임 확장 (0) | 2021.01.09 |
---|---|
R기초; 데이터프레임 생성 (0) | 2021.01.06 |
R 기초; 리스트 인덱싱-1 (0) | 2021.01.05 |
R기초; 리스트 생성 (0) | 2021.01.04 |
R 기초; 배열 (0) | 2021.01.04 |
댓글