-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists.R
More file actions
51 lines (35 loc) · 1.38 KB
/
Copy pathlists.R
File metadata and controls
51 lines (35 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# A list in R can contain many different data types inside it. A list is a collection of data which is ordered and changeable.
thislist <- list("apple", "banana", "cherry") # List of strings
thislist # Print the list
# ACCESS LIST
thislist <- list("apple", "banana", "cherry")
thislist[[2]]
# CHANGE ITEM VALUE
# To change the value of a specific item, refer to the index number:
thislist <- list("apple", "banana", "cherry")
thislist[1] <- "blackcurrant"
thislist # Print the updated list
# LIST LENGTH
thislist <- list("apple", "banana", "cherry")
length(thislist)
# CHECK IF ITEM EXITS
thislist <- list("apple", "banana", "cherry")
"apple" %in% thislist
# ADD LIST ITEMS
thislist <- list("apple", "banana", "cherry")
append(thislist, "orange")
# To add an item to the right of a specified index, add "after=index number" in the append() function:
thislist <- list("apple", "banana", "cherry")
append(thislist, "orange", after = 2) # Add "orange" to the list after "banana" (index 2)
# REMOVE LIST ITEMS
thislist <- list("apple", "banana", "cherry")
newlist <- thislist[-1] # remove "apple" from the list
newlist # Print the new list
# RANGE OF INDEXS
thislist <- list("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
thislist[2:5]
# JOIN 2 LISTS
list1 <- list("a", "b", "c")
list2 <- list(1,2,3)
list3 <- c(list1,list2)
list3