foods <- list('Fish', 'Meat', 'Chicken', 'Cheese', 'Milk', 'Butter', 'Eggs', 'Vegetables', 'Fruits', 'Rice', 'Bread')

for(i in foods){
  cat("I buy some food: ", i, ".\n", sep="")
}
## I buy some food: Fish.
## I buy some food: Meat.
## I buy some food: Chicken.
## I buy some food: Cheese.
## I buy some food: Milk.
## I buy some food: Butter.
## I buy some food: Eggs.
## I buy some food: Vegetables.
## I buy some food: Fruits.
## I buy some food: Rice.
## I buy some food: Bread.
length(foods)
## [1] 11
foods[2]
## [[1]]
## [1] "Meat"
foods[1] <- "Bananas"
foods
## [[1]]
## [1] "Bananas"
## 
## [[2]]
## [1] "Meat"
## 
## [[3]]
## [1] "Chicken"
## 
## [[4]]
## [1] "Cheese"
## 
## [[5]]
## [1] "Milk"
## 
## [[6]]
## [1] "Butter"
## 
## [[7]]
## [1] "Eggs"
## 
## [[8]]
## [1] "Vegetables"
## 
## [[9]]
## [1] "Fruits"
## 
## [[10]]
## [1] "Rice"
## 
## [[11]]
## [1] "Bread"
#Check if item exists

if("Milk" %in% foods){
  print("TRUE")
}else{
  print("FALSE")
}
## [1] "TRUE"
#Add list items

append(foods, "Steak")
## [[1]]
## [1] "Bananas"
## 
## [[2]]
## [1] "Meat"
## 
## [[3]]
## [1] "Chicken"
## 
## [[4]]
## [1] "Cheese"
## 
## [[5]]
## [1] "Milk"
## 
## [[6]]
## [1] "Butter"
## 
## [[7]]
## [1] "Eggs"
## 
## [[8]]
## [1] "Vegetables"
## 
## [[9]]
## [1] "Fruits"
## 
## [[10]]
## [1] "Rice"
## 
## [[11]]
## [1] "Bread"
## 
## [[12]]
## [1] "Steak"
append(foods, "Sausage", after = 2)
## [[1]]
## [1] "Bananas"
## 
## [[2]]
## [1] "Meat"
## 
## [[3]]
## [1] "Sausage"
## 
## [[4]]
## [1] "Chicken"
## 
## [[5]]
## [1] "Cheese"
## 
## [[6]]
## [1] "Milk"
## 
## [[7]]
## [1] "Butter"
## 
## [[8]]
## [1] "Eggs"
## 
## [[9]]
## [1] "Vegetables"
## 
## [[10]]
## [1] "Fruits"
## 
## [[11]]
## [1] "Rice"
## 
## [[12]]
## [1] "Bread"
#remove list items

new_foods <- foods[-1]
new_foods
## [[1]]
## [1] "Meat"
## 
## [[2]]
## [1] "Chicken"
## 
## [[3]]
## [1] "Cheese"
## 
## [[4]]
## [1] "Milk"
## 
## [[5]]
## [1] "Butter"
## 
## [[6]]
## [1] "Eggs"
## 
## [[7]]
## [1] "Vegetables"
## 
## [[8]]
## [1] "Fruits"
## 
## [[9]]
## [1] "Rice"
## 
## [[10]]
## [1] "Bread"
#Join two lists

birds <- list('Owl', 'Sparrow', 'Woodpecker', 'Eagle', 'Hummingbird', 'Penguin', 'Duck', 'Goose', 'Peacock', 'Pigeon', 'Robin')

fruits <- list('Cherries', 'Apple', 'Persimmon', 'Peach', 'Fig', 'Kiwi', 'Avocado', 'Lychee', 'Grapes', 'Watermelon')

birds_fruits <- c(birds, fruits)
birds_fruits
## [[1]]
## [1] "Owl"
## 
## [[2]]
## [1] "Sparrow"
## 
## [[3]]
## [1] "Woodpecker"
## 
## [[4]]
## [1] "Eagle"
## 
## [[5]]
## [1] "Hummingbird"
## 
## [[6]]
## [1] "Penguin"
## 
## [[7]]
## [1] "Duck"
## 
## [[8]]
## [1] "Goose"
## 
## [[9]]
## [1] "Peacock"
## 
## [[10]]
## [1] "Pigeon"
## 
## [[11]]
## [1] "Robin"
## 
## [[12]]
## [1] "Cherries"
## 
## [[13]]
## [1] "Apple"
## 
## [[14]]
## [1] "Persimmon"
## 
## [[15]]
## [1] "Peach"
## 
## [[16]]
## [1] "Fig"
## 
## [[17]]
## [1] "Kiwi"
## 
## [[18]]
## [1] "Avocado"
## 
## [[19]]
## [1] "Lychee"
## 
## [[20]]
## [1] "Grapes"
## 
## [[21]]
## [1] "Watermelon"