Chapter 3 Basic R

Xin Guo, Aiden Zhang

R is a tool for data processing, it is important for us to understand the basic operations. In this cheatsheat/tutorial we will cover some basic operations of data. We will start with the building blocks of data types then go to the data structures. We try to cover the create, update(delete included), select operations for each data object following the logic of basic database operations.

3.1 Data types

For different data types, the attributes of an object is of most interest, we would use the following functions to explore objects.

We will classify them into two types, one is the read-only functions, and the others are writable functions. If we want to change the attributes of an object, we might use some functions to implement, and we will also cover these operations.

3.1.1 (1) character

Let us explore the attributes of the character. The following are some of the general “read-only” functions.

##    Length     Class      Mode 
##         1 character character

str function returns some information, but it is less detailed than the summary.

##  chr "hellow world"

summary and str are efficient functions to know about an object, but it is worth noticed that function attributes does not give us information about the variable.

## NULL

Then let us explore more about the “read-only” functions and get to know the functions that can change their return values.

length function will return the length of the object.

## [1] 1

We can change the length of the object by appending another character to it. If we want append a number to it, the number will be converted into a character to be consistent.

## [1] 2

unique function returns the unique element in the object.

## [1] "hellow world"

For each unique element in the object, table function returns their frequencies. range function returns the minimum and maximum value.

## temp_char
## hellow world 
##            1
## [1] "hellow world" "hellow world"

We can change the value of the character by using the substr function. If we want to add more value to the end, we can use the paste function.It will return a longer size character object. If we add a number using paste, like the append function, it will convert the number into character. This is useful when we have a different data to print out and the print function cannot support multiple items.

## [1] "hello? world!2019"

We can use the class function to find out the data type of this object.

## [1] "character"

If we want to change the class of this object, we would normally use the as function. We might try to turn a number into character sometimes.

## [1] "numeric"
## [1] "character"

We should pay attention to that the as function does not modify the parameter passed into it. So we will have a new object.

Now, let us look at some writable attributes of the object. Levels is the order for the items in the object, that is why a character object will not have order. We can set the levels though it does not have any meaning for this certain character. It will not change the data type of the object.

## NULL
## [1] 1
## [1] "character"

names function will return the name of an object if it has, and we can assign value to it to name the object. The dimension and the length of the names we want to assign must match the dimension and length of the object, otherwise it will return error.

## NULL

Other attributes related to names are rownames, colnames and dimnames, since this object does not have dimension, so it will return values NULL and it will not allow us to make any changes to them.

## NULL
## NULL
## NULL

3.1.2 (2)numeric

There are two types of numerical data in R, numeric and integer. We will use the numeric class as interpretation since integer can be regarded as a specific kind of numeric.

Let us explore the attributes of the numeric object. The following are some of the general “read-only” functions. Based on different object passed into the function, the summary will give us different details about the object.

##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    3.14    3.14    3.14    3.14    3.14    3.14

str function returns the class and value information.

##  num 3.14

attributes function still does not give us information about the object.

## NULL

Then let us explore more about the “read-only” functions and get to know the functions that will change their return values.

length function will return the length of the object.

## [1] 1

We can change the length of the object by appending another numeric number to it.

## [1] "numeric"
## [1] 2

unique function returns the unique element in the object.

## [1] 3.14

For each unique element in the object, table function returns their frequencies. range function returns the lowest and largest values in the input vector

## temp_numer
## 3.14 
##    1
## [1] 3.14 3.14

To change the value of a numeric object, we usually reassign the value of it.

class function can find out the data type of this object.

## [1] "numeric"

If we want to change the class of this object, we would normally use the as function. We might try to turn character into a numeric data. The function only works if it makes sense. We cannot turn a character of “hello world” into a number, the function will return error.

## [1] 3.14
## [1] "numeric"

We should pay attention to that the as function does not modify the parameter passed into it. So we will have a new object.

And if we try to turn a character into a integer, we can see that if it is a real number in meaning, it will be converted into a integer at the output.

## [1] 2

It will have problem when the character is not in a good format, for example with a comma. We need to fix the comma problem before we transform the class type. Here, gsub and sub does not have a functional difference, because the matching pattern is not a regular expression. gsub is more powerful and strict in matching pattern when regular expression is used.

## [1] NA
## [1] NA
## [1] 1234
## [1] 1234

Now, let us look at some writable attributes of the object. Levels can be modified but still does not effect the class type of the numeric object.

## NULL
## [1] 1
## [1] "numeric"

names function will return the name of an object if it has, and we can assign value to it to name the object.

## NULL

Other attributes related to names are rownames, colnames and dimnames, since this object does not have dimension, so it will return values NULL and it will not allow us to make any changes to them.

## NULL
## NULL
## NULL

3.1.3 (3)Logical

logical data is the data that contains TRUE and FALSE, or you can abbreviate them as T and F in R. We can easily convert between logicals and numericals with 1 and 0.

## [1] 1 0 1 1 0
## [1]  TRUE FALSE  TRUE  TRUE FALSE

Let us explore the attributes of the logicals. The following are some of the general “read-only” functions. Based on different object passed into the function, the summary will give us different details about the object.

##    Mode   FALSE    TRUE 
## logical       2       3

str function returns the some information, it is less detailed than the summary.

##  logi [1:5] TRUE FALSE TRUE TRUE FALSE

For each unique element in the object, table function returns their frequencies. range function returns the lowest and largest values in the input vector.

## [1] 0 1
## temp_logical
## FALSE  TRUE 
##     2     3

There are many useful functions related to logicals. We will illustrate a few here:

ifelse(<logical>, value1, value2) returns value1 if logical is true, return value2 if logical is false. It is especially useful when we need to inspect or modify data based on its value. Note that this function takes a vector.

## [1] FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE
## [1] 1 0 1 0 2 2 3 4

Now we have all NA values changed to 0.

all(<logical vector>) returns if all the logical values are true.

## [1] FALSE

Not all values of temp are NAs.

any(<logical vector>) returns if any of the logical values are true

## [1] TRUE

There exists an NA value in temp.

which(<logical vector>) return the index which the logical value is true

## [1] 2 4

The element at indexes 2 and 4 of temp are NAs.

The basic classes of R includes numeric, logical, character, integer, complex, since numeric, character, logical are the most common ones, so we illustrated these 3 classes. Complex is a broader range than the real number, in reality, the data we collect will rarely relate to it.

Now we will head to different data structures.

3.2 data structure

3.2.1 (1) vector:

A vector can only contain objects from the same class. We can use these two ways to create a vector. It will lead different operations when we want to update this vector object. There is no better between these two methods, they should be used according to our coding needs.

Let us explore the attributes of the vector. The following are some of the general “read-only” functions.

##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     1.0     1.5     2.0     2.0     2.5     3.0
##  num [1:3] 1 2 3
## NULL

Then let us explore more about the “read-only” functions and get to know the functions that will change their return values.

length function will return the length of the object.

## [1] 3

We can change the length of the object by appending another character to it. If we want append a number to a character vector, the number will be converted into a character to be consistent.

## [1] "numeric"
## [1] 4

unique function returns the unique element in the object.

## [1] 1 2 3

For each unique element in the object, table function returns their frequencies. range function returns the maximum and minimum values.

## temp_vector
## 1 2 3 
## 1 1 1
## [1] 1 3
## [1] "a" "c"

To update the value of a vector object, we use the index to access and change that value.

## [1] 1.1 2.0 3.0

match function can be used to find the corresponding item based on value and update its values. which function can be used to find all the matches.

This is like the relationship between regexpr and gregexpr, where regexpr only gives you the first match of the string (reading left to right) and gregexpr will return all of the matches in a given string if there are is more than one match.

For character vector, we might also use gregexpr if we look for certain items with some patterns.

## [1] 1.1 2.0 3.0
## [1] 1.1 2.0 3.0
## [1] "a" "b"
## [1] "a" "b"

If we want to change the values of some items within specific range of values, we can use the logical expression to subset them.

## [1] 1.1 2.0
## [1] 1 1
## [1] 2.1 3.0

class function can find out the data type of this object.

We can see that the class type for vector is not vector but the data type of the item inside the vector.

## [1] "numeric"
## [1] "numeric"
## [1] "character"

If we want to change the class of this object, we would normally use the as function. We might try to use the sapply functions. We might try to turn character into a numeric data. The function only works if it makes sense.

The sapply function behaves similarly to lapply; the only real difference is in the return value. sapply will try to simplify the result of lapply.

## 3.14 2.72 
## 3.14 2.72
## [[1]]
## [1] 3.14
## 
## [[2]]
## [1] 2.72

We should pay attention to that the as function does not modify the parameter passed into it. So we will have a new object.

Now, let us look at some writable attributes of the object. Levels is NULL and can be modified but still does not effect the class type of the numeric object.

## NULL
## [1] "numeric"

names function will return the name of an object if it has, and we can assign value to it to name the object. Then we will be able to access the items with their names.

## NULL
## alpha 
##   1.1

If we want to find some items with certain names, we can find them in the following ways.

## alpha 
##   1.1

Other attributes related to names are rownames, colnames and dimnames, since this object does not have dimension, so it will return values NULL and it will not allow us to make any changes to them.

## NULL
## NULL
## NULL

3.2.2 (2)list:

A list can contain objects from the different classes. We can use two ways to create a list.

Let us explore the attributes of the list. The following are some of the general “read-only” functions.

##    Length Class  Mode     
## a  2      -none- numeric  
##    1      -none- numeric  
## pi 1      -none- numeric  
## c  1      -none- character
## List of 4
##  $ a : num [1:2] 1 2
##  $   : num 2.72
##  $ pi: num 3.14
##  $ c : chr "hello world"
## List of 5
##  $ : NULL
##  $ : NULL
##  $ : NULL
##  $ : NULL
##  $ : NULL
## $names
## [1] "a"  ""   "pi" "c"

Then let us explore more about the “read-only” functions and get to know the functions that will change their return values.

length function will return the length of the object.

## [1] 4

We can change the length of the object by append function.

## [1] "list"
## [1] 5

unique function returns the unique element in the object.

## [[1]]
## [1] 1 2
## 
## [[2]]
## [1] 2.72
## 
## [[3]]
## [1] 3.14
## 
## [[4]]
## [1] "hello world"

For each unique element in the object,we cannot use the table function directly but to apply it to each item of the the object. range function returns the maximum and minimum values.

## $a
## 
## 1 2 
## 1 1 
## 
## [[2]]
## 
## 2.72 
##    1 
## 
## $pi
## 
## 3.14 
##    1 
## 
## $c
## 
## hello world 
##           1
## [1] "1"           "hello world"

To update the value of a vector object, we use the index/name to access and change that value.

The following three ways can be used to acces and modify an object in the list.

## [1] 1 2
## [1] 1 3

The following indexings are used to access the first item, it is worth noticed that it returns the whole item including its value.

## $a
## [1] 1 3
## $a
## [1] 1 3
## $a
## [1] 1 3

If we want to find the nested element in an item of a list, we will use the following ways to select.

## [1] 1
## [1] 2

class function can find out the data type of this object.

## [1] "list"

Now, let us look at some writable attributes of the object. Levels is NULL and can be modified but still does not effect the class type of the numeric object.

## NULL
## [1] "list"

names function will return the name of an object if it has, and we can assign value to it to name the object. Recall previously that we cannot name the item when appending it, but we can name it later.

## [1] "a"  ""   "pi" "c"

If we want to find some items with certain names, we can find them in the following ways.

## $e
## [1] 2.72
## 
## $c
## [1] "hello world"

Other attributes related to names are rownames, colnames and dimnames, since this object does not have dimension, so it will return values NULL and it will not allow us to make any changes to them.

## NULL
## NULL
## NULL

3.2.3 (3)factor

Often factors will be automatically created when we read a dataset in using a function like read.table().

factor function will create a factor array.

Let us explore the attributes of the factor. The following are some of the general “read-only” functions.

##  no yes 
##   2   3
##  Factor w/ 2 levels "no","yes": 2 2 1 2 1

attributes function tells us the levels of the factor, it is set by default. And we can know from the str function that “no” corresponds to the level 1 and “yes” to 2.

## $levels
## [1] "no"  "yes"
## 
## $class
## [1] "factor"

Then let us explore more about the “read-only” functions and get to know the functions that will change their return values.

length function will return the length of the object.

## [1] 5

It is not common to add new item into a factor, we can try using the append function to do it. And we have found that during the append operation, the function takes the levels attribute to do the work. So if we append a character to it, the resulting object is a character vector and so does the numeric object. So this is not a proper operation and it would be better if we create a vector than turn it into a factor with as.factor or factor function.

## [1] yes yes no  yes no 
## Levels: no yes
## [1] "factor"
## [1] "2"  "2"  "1"  "2"  "1"  "no"
## $a
## [1] 1 2
## 
## [[2]]
## [1] 2.72
## 
## $pi
## [1] 3.14
## 
## $c
## [1] "hello world"
## 
## [[5]]
## [1] 0

unique function returns the unique element in the object.

## [1] yes no 
## Levels: no yes

For each unique element in the object, table function returns their frequencies. range function does not have meanings under the level order, so it will return error.

## temp_factor
##  no yes 
##   2   3

To update the value of a vector object, we use the index to access and change that value. We can only modify the value within the current levels, out of scope modification will return error, which means we cannot assign value like “neutral” to the item inside the factor.

## [1] no  yes no  yes no 
## Levels: no yes

match function can be used to find the corresponding item based on value and update its values. which function can be used to find all the matches. Then we can use the sapply function to modify the value of the elements.

## [1] no  yes no  yes no 
## Levels: no yes
## [1] yes no 
## Levels: no yes
## [1] no  yes no  yes no 
## Levels: no yes

class function can find out the data type of this object.

## [1] "factor"

Now, let us look at some writable attributes of the object. levels function returns the default level, we would try to reset the order with the factor function. We should notice that though we can modify the levels directly, but this will not return the desired result, so we should not use this way to modify it.

## [1] "no"  "yes"
## [1] no  no  yes yes yes
## Levels: no yes
## [1] yes yes yes no  no 
## Levels: yes no
## [1] yes yes no  no  no 
## Levels: yes no
## [1] yes yes yes no  no 
## Levels: yes no

names function will return the name of an object if it has, and we can assign value to it to name the object. Then we will be able to access the items with their names.

## NULL
## alpha 
##   yes 
## Levels: no yes

If we want to find some items with certain names, we can find them in the following ways.

## alpha 
##   yes 
## Levels: no yes

Other attributes related to names are rownames, colnames and dimnames, since this object does not have dimension, so it will return values NULL and it will not allow us to make any changes to them.

## NULL
## NULL
## NULL

3.2.4 (4)matrix

matrix is a data structure with dimensions. matrix function will create a matrix.

Let us explore the attributes of the factor. The following are some of the general “read-only” functions.

##        V1          V2          V3          V4          V5   
##  Min.   :0   Min.   :0   Min.   :0   Min.   :0   Min.   :0  
##  1st Qu.:0   1st Qu.:0   1st Qu.:0   1st Qu.:0   1st Qu.:0  
##  Median :0   Median :0   Median :0   Median :0   Median :0  
##  Mean   :0   Mean   :0   Mean   :0   Mean   :0   Mean   :0  
##  3rd Qu.:0   3rd Qu.:0   3rd Qu.:0   3rd Qu.:0   3rd Qu.:0  
##  Max.   :0   Max.   :0   Max.   :0   Max.   :0   Max.   :0
##  num [1:2, 1:5] 0 0 0 0 0 0 0 0 0 0
## $dim
## [1] 2 5

Then let us explore more about the “read-only” functions and get to know the functions that will change their return values.

length function will return the length of the object, the length is calculated by multiplying dimensions.

## [1] 10
## [1] 2
## [1] 5
## [1] 10

If we want to add another matrix into the current matrix, we will use the rbind and cbind functions. rbind means binding along the row, so it will require the column sizes of two matrices are the same. cbind means binding along the column, so it will require the row sizes of two matrices are the same.

append function does not work, because it would turn the matrix into a 1 dimensions data structure which is not we want.

## NULL
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    0    0    0    0    0
## [2,]    0    0    0    0    0

unique function returns the unique element in the object.

##      [,1] [,2] [,3] [,4] [,5]
## [1,]    0    0    0    0    0
## [2,]    0    3    0    0    0

For each unique element in the object, table function returns their frequencies. range will return the minimum and maximum object. The operations are done across the matrix, not confined to certain row or column.

## temp_matrix
## 0 3 
## 9 1
## [1] 0 3

To update the value of a matrix object, we use the index to access and change that value. We cannot update with a different data type.

##      [,1] [,2] [,3] [,4] [,5]
## [1,]    0    0    0    0    0
## [2,]    0    3    0    0    0
## [1] 0 3 0 0 0
## [1] 1 3

Random access item like this will return value by spreading the matrix.

## [1] 3

The in function can help us to determine if an value falls into our criteria, we directly use the TRUE and False result to subset the matrix we want. When using the which function, we need to be careful that we are selecting rows so that the subset format should be correct.

Then we can use the sapply function to modify the value of the elements.

##      [,1] [,2] [,3] [,4] [,5]
## [1,]    0    1    0    0    0
## [2,]    0    3    0    0    0
## [1] FALSE  TRUE
## [1] 0 3 0 0 0
## [1] 2
## [1] 0 3 0 0 0

class function can find out the data type of this object.

## [1] "matrix"

Now, let us look at some writable attributes of the object. levels function returns NULL because this is not a factor matrix. We create a factor matrix but it will lose the attributes as a factor when we apply matrix operations to it. So levels does not have significant meaning in matrix.

## NULL

names function will return the name of an object if it has, and we can assign value to it to name the object. Then we will be able to access the items with their names.

##      [,1] [,2] [,3] [,4] [,5]
## [1,]    0    1    0    0    0
## [2,]    0    3    0    0    0
## attr(,"names")
##  [1] "1" "2" "3" "4" "5" "6" "7" "8" NA  NA
## 3 
## 1

If we want to find some items with certain names, we can find them in the following ways.

## 4 5 6 
## 3 0 0

But selecting a single item is not usually what we want, we might want to select a whole column/row based on its name.

Other attributes related to names are rownames, colnames and dimnames, the dimensions of the assignment value must match the matrix size.

##   a b c d e
## 1 0 1 0 0 0
## 2 0 3 0 0 0
## attr(,"names")
##  [1] "1" "2" "3" "4" "5" "6" "7" "8" NA  NA

To access or update value with their names we use the following format.

## a b c d e 
## 0 1 0 0 0
## 1 2 
## 0 0

3.2.5 (5) dataframe

Data frames are usually created by reading in a dataset using the read.table() or read.csv(). Each column can be viewed as a vector. And can be viewed as list with vectors of same length. We load a dataframe from the basic R data function

Let us explore the attributes of the factor. The following are some of the general “read-only” functions.

##      height         weight     
##  Min.   :58.0   Min.   :115.0  
##  1st Qu.:61.5   1st Qu.:124.5  
##  Median :65.0   Median :135.0  
##  Mean   :65.0   Mean   :136.7  
##  3rd Qu.:68.5   3rd Qu.:148.0  
##  Max.   :72.0   Max.   :164.0
## 'data.frame':    15 obs. of  2 variables:
##  $ height: num  58 59 60 61 62 63 64 65 66 67 ...
##  $ weight: num  115 117 120 123 126 129 132 135 139 142 ...
## $names
## [1] "height" "weight"
## 
## $class
## [1] "data.frame"
## 
## $row.names
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15

Then let us explore more about the “read-only” functions and get to know the functions that will change their return values.

length function will return the length of the object, the length is calculated by multiplying dimensions.

## [1] 2
## [1] 15
## [1] 2
## [1] 15  2

If we want to add another dataframe into the current matrix, we will use the rbind method because this is a new observation. If we want to add a new variable then we will use cbind.

## [1] 16  2

unique function returns the unique element in the object.

##    height weight
## 1      58    115
## 2      59    117
## 3      60    120
## 4      61    123
## 5      62    126
## 6      63    129
## 7      64    132
## 8      65    135
## 9      66    139
## 10     67    142
## 11     68    146
## 12     69    150
## 13     70    154
## 14     71    159
## 15     72    164

For each unique element in the object, table function returns their frequencies. range will return the minimum and maximum object. The operations are done across the matrix, not confined to certain row or column.

##       weight
## height 115 117 120 123 126 129 132 135 139 142 146 150 154 159 164
##     58   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
##     59   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0
##     60   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
##     61   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0
##     62   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0
##     63   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
##     64   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
##     65   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0
##     66   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
##     67   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0
##     68   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0
##     69   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0
##     70   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0
##     71   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
##     72   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1
## [1]  58 164

To update the value of a dataframe item, we use the index to access and change that value. We cannot update with a different data type.

## [1] 120
##   height weight
## 2     59    117
##  [1] 115 117 120 123 126 129 132 135 139 142 146 150 154 159 164

Random access item like this will return the 1st column value of the dataframe which is different from the matrix operation.

##    height
## 1      58
## 2      59
## 3      60
## 4      61
## 5      62
## 6      63
## 7      64
## 8      65
## 9      66
## 10     67
## 11     68
## 12     69
## 13     70
## 14     71
## 15     72

To change the values in a row or in a column, we can use sapply function or vectorized function to modify the data. And if we want to apply changes to all the rows/columns, we will use the apply function. To create new variable based on the other variables, we will use the mapply function.

##    height weight
## 1      58    115
## 2      59    117
## 3      60    120
## 4      61    123
## 5      62    126
## 6      63    129
## 7      64    132
## 8      65    135
## 9      66    139
## 10     67    142
## 11     68    146
## 12     69    150
## 13     70    154
## 14     71    159
## 15     72    164
##    height weight
## 1      58    115
## 2      59    117
## 3      60    120
## 4      61    123
## 5      62    126
## 6      63    129
## 7      64    132
## 8      65    135
## 9      66    139
## 10     67    142
## 11     68    146
## 12     69    150
## 13     70    154
## 14     71    159
## 15     72    164
##  [1] 0.03418549 0.03361103 0.03333333 0.03305563 0.03277836 0.03250189
##  [7] 0.03222656 0.03195266 0.03191001 0.03163288 0.03157439 0.03150599
## [13] 0.03142857 0.03154136 0.03163580

To subset some dataframe, we use the in function and the which function. We need to be careful that we are selecting rows so that the subset format should be correct, unlike matrix, when in function can be easily converted to the result we want.

And we can also use the split function and then access the part we want with corresponding index.

##   height weight
## 2     59    117
## 3     60    120
##   height weight
## 2     59    117
## 3     60    120

class function can find out the data type of this object.

## [1] "data.frame"

Now, let us look at some writable attributes of the object. levels function returns NULL even if the dataframe contains factor variables.

## NULL

names function will return the name of an object if it has, and we can assign value to it to name the object. Then we will be able to access the items with their names. Unlike matrix, in dataframe the names is for the column names, so by names, we will access a column.

## [1] "height" "weight"
##     1
## 1  58
## 2  59
## 3  60
## 4  61
## 5  62
## 6  63
## 7  64
## 8  65
## 9  66
## 10 67
## 11 68
## 12 69
## 13 70
## 14 71
## 15 72

Other attributes related to names are rownames, colnames and dimnames, the dimensions of the assignment value must match the matrix size.

##  [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15"
## [1] "1" NA
## [[1]]
##  [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15"
## 
## [[2]]
## [1] "1" NA

To access or update value with their names we use the following format.

##    1  NA
## 1 58 115
##  [1] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72