# 7-1 Creating and editing lists

# Create a list with multiple data types

j<-list(name="Jack", age=22, overseas=F)

# Display list

j

# name, age and overseas are tags
# These can be ignored, but the resulting data structure
# is a bit more confusing

j<-list("Jack", 22, F)

# Display list

j

# Tags are useful, so let's put them back

j<-list(name="Jack", age=22, overseas=F)

# Three ways of accessing a list component

j$age              # Using the tag
j[["age"]]         # Using the tag as an index
j[[2]]             # Using a numerical index

# Double brackets return a value as its atomic class

class(j[[2]])

# Single brackets return a value as a list

class(j[2])

# Single brackets are useful for accessing multiple elements

j[1:2]

# The backticks around the first element name seem to be a bug in 
# the current version of R