Introduction to Lists in R

In the video tutorial below you will learn how to create and use lists in R.  Below the video tutorial you will find the code used in the tutorial.


Here is the code used in the video.

#######################################
###  Working with Lists in R
#######################################

# Create a simple vector
vec1 <- c(0, 1, 2, 3, 4, 5)

# Create a text vector
vec2 <- c("Bob", "John", "Sally")

# Create a simple matrix
mat1 <- matrix(
               c( 12, 3,
                   4, 8),
               ncol=2,
               nrow=2
               )

# Combine them into a list
mylist1 <- list(vec1, vec2, mat1)
mylist1

# Combine them into a list with names
mylist2 <- list(numbers = vec1, people=vec2, m1 = mat1)
mylist2

# Pull an item from the list
mylist1[[2]]
mylist2$people


If you have any questions please ask.

1 comment:

  1. Thanks Dr. Boone!

    I found your "Intro to Stats with R" video in YouTube, and then I fumbled about a bit till I found this web page. Very nice!

    - Bill

    ReplyDelete