R Tutorials
R Data Structures
R Graphics
R Statistics
R Examples
List R can contain many different types of data within it. List a single and flexible data collection.
To create a list, use the list()
function:
You can access the list items by referring to its reference number, inside brackets. The first item has point 1, the second item has point 2, and so on:
To change the value of an item, see the reference number:
To find out how many items the list has, use the length()
function:
To find out if something is listed, use %in%
operator:
To add an item to the end of the list, use the append()
function:
Add "orange" to the list:
To add an item to the right of a specific index, add "after = index number
" to the append()
function:
Add "orange" to the list after "banana"(index 2):
You can also delete list items. The following example creates a new, updated list without the "apple" item:
Remove "apple" from the list:
You can specify a range of indicators by specifying where to start and where to end the range, using :
operator:
Return the second, third, fourth and fifth item:
Note: Search will start in index 2 (included) and end in index 5 (included).
Remember that the first item has index 1.
You can access the list items by using the for
loop:
There are several ways to join, or merge, two or more columns in R.
The most common method is to use the c()
function, which combines two elements together: