This repository was archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path13.cbind_and_rbind.r
More file actions
87 lines (82 loc) · 1.5 KB
/
13.cbind_and_rbind.r
File metadata and controls
87 lines (82 loc) · 1.5 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Aim: Write an R Program to create a Matrix using cbind() and rbind() functions.
# Source Code:
Make_Matrix = function()
{
c = as.integer(readline("Enter the no. of columns : "))
r = as.integer(readline("Enter the no. of rows : "))
cat("\nCreate a matrix using cbind :-\n\n")
mat_A = cbind()
m = 0
for( i in 1:c )
{
cat("Enter the element of column",i," : ")
for( j in 1:r )
m[j] = as.numeric(readline())
mat_A = cbind(mat_A,m)
}
print(mat_A)
cat("\nCreate a matrix using rbind :-\n\n")
mat_B = rbind()
for( i in 1:r )
{
cat("Enter the element of row",i," : ")
for( j in 1:c )
m[j] = as.numeric(readline())
mat_B = rbind(mat_B,m)
}
print(mat_B)
rm(c)
rm(r)
rm(m)
rm(mat_A)
rm(mat_B)
}
Make_Matrix()
# INPUT/OUTPUT:
# Enter the no. of columns : 4
# Enter the no. of rows : 3
#
# Create a matrix using cbind :-
#
# Enter the element of column 1 :
# 1
# 2
# 3
# Enter the element of column 2 :
# 4
# 5
# 6
# Enter the element of column 3 :
# 7
# 8
# 9
# Enter the element of column 4 :
# 10
# 11
# 12
# m m m m
# [1,] 1 4 7 10
# [2,] 2 5 8 11
# [3,] 3 6 9 12
#
# Create a matrix using rbind :-
#
# Enter the element of row 1 :
# 1
# 2
# 3
# 4
# Enter the element of row 2 :
# 5
# 6
# 7
# 8
# Enter the element of row 3 :
# 9
# 10
# 11
# 12
# [,1] [,2] [,3] [,4]
# m 1 2 3 4
# m 5 6 7 8
# m 9 10 11 12