[emaillocker]Below are the solutions to these exercises on lists.

# Exercise 1 p <- c(2,7,8) q <- c("A", "B", "C") x <- list(p, q) x[2]

## [[1]] ## [1] "A" "B" "C"

# (Answer: b) # Exercise 2 w <- c(2, 7, 8) v <- c("A", "B", "C") x <- list(w, v) x[[2]][1] <- "K" x

## [[1]] ## [1] 2 7 8 ## ## [[2]] ## [1] "K" "B" "C"

# (Answer: b) # Exercise 3 a <- list ("x"=5, "y"=10, "z"=15) sum(unlist(a))

## [1] 30

# (Answer: c) # Exercise 4 Newlist <- list(a=1:10, b="Good morning", c="Hi") Newlist$a <- Newlist$a + 1 Newlist

## $a ## [1] 2 3 4 5 6 7 8 9 10 11 ## ## $b ## [1] "Good morning" ## ## $c ## [1] "Hi"

# Exercise 5 b <- list(a=1:10, c="Hello", d="AA") b$a[-2]

## [1] 1 3 4 5 6 7 8 9 10

# Exercise 6 x <- list(a=5:10, c="Hello", d="AA") x$z <-"New Item" x

## $a ## [1] 5 6 7 8 9 10 ## ## $c ## [1] "Hello" ## ## $d ## [1] "AA" ## ## $z ## [1] "New Item"

# Exercise 7 y <- list("a", "b", "c") names(y) <- c("one", "two", "three") y

## $one ## [1] "a" ## ## $two ## [1] "b" ## ## $three ## [1] "c"

# Exercise 8 x <- list(y=1:10, t="Hello", f="TT", r=5:20) length(x$r)

## [1] 16

# Exercise 9 string <- "Grand Opening" a <- strsplit(string," ") list(a[[1]][1], a[[1]][2])

## [[1]] ## [1] "Grand" ## ## [[2]] ## [1] "Opening"

# Exercise 10 y <- list("a", "b", "c") q <- list("A", "B", "C", "a", "b", "c") setdiff(q, y)

## [[1]] ## [1] "A" ## ## [[2]] ## [1] "B" ## ## [[3]] ## [1] "C"

[/emaillocker]

Carlos says

Thank you for the exercises.