IDS-Unit 3
IDS-Unit 3
Let see an example to understand how elements are accessed from the matrix
present on nth row mth column, nth row, or mth column.
, , Matrix2
Col1 Col2 Col3
Row1 1 10 13
Row2 3 11 14
Row3 5 12 15
,,1 ,,2
[,1] [,2] [,3] [,1] [,2] [,3]
[1,] 1 10 13 [1,] 1 10 13
[2,] 3 11 14 [2,] 3 11 14
[3,] 5 12 15 [3,] 5 12 15
Changing Levels:
You can also modify levels using the levels() function.
# Changing levels of a factor
levels(gender_factor) <- c("F", "M")
print(gender_factor)
Output:
Name Age Salary
2 Bob 30 60000
1 Alice 25 50000
3 Charlie 22 55000
$<NA>
NULL
$Course
[1] "Masters of computer applications"
list2 <-list(5:14)
print(list2)
# Converting the lists to vectors.
v1 <- unlist(list1)
v2 <- unlist(list2)
print(v1)
print(v2)
[[1]]
[1] 5 6 7 8 9 10 11 12 13 14
[1] 10 11 12 13 14 15 16 17 18 19 20
[1] 5 6 7 8 9 10 11 12 13 14