-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26_R_Lists.R
More file actions
59 lines (47 loc) · 1.09 KB
/
Copy path26_R_Lists.R
File metadata and controls
59 lines (47 loc) · 1.09 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
52
53
54
55
56
57
58
59
# R_Lists
# Example 1
list1 <- list('apple','banana','mango')
print(list1)
print('----------')
# Accessing a list item
print(list1[1])
print('----------')
# Changing a list item
list1[1] <- 'cherry'
print(list1)
print('----------')
# List length
print(length(list1)) # 3
print('----------')
# Checking if an item exist inside a list
value <- 'mango' %in% list1
print(value) # TRUE
print('----------')
# Adding a list item to an existing list
list1_extended <- append(list1, 'Orange')
print(list1_extended)
print('----------')
list1_extended2 <- append(list1_extended, 'pineapple', after = 2)
print(list1_extended2)
print('----------')
# Removing a list item
print(list1)
print('----------')
list2 <- list1[-1]
print(list2)
print('----------')
# Range of Indexces
list3 <- list("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
print(list3[2:4])
print('----------')
# Looping through a list
for (x in list3) {
print(x)
}
print('----------')
# Joining two list items
list4 <- list('a','b','c')
list5 <- list(1,2,3,4)
join_lists <- c(list4, list5)
print(join_lists)
print('----------')