Professional Documents
Culture Documents
SECTION: G
1. LIST:
#create a list
Print (list1)
OUTPUT
#create a matrix
Print (M)
Rownames = c ("row1","row2","row3","row4")
Colnames = c ("col1","col2","col3")
Print (p)
OUTPUT
[, 1] [, 2] [, 3] [, 4] [, 5]
[1,] 2 3 4 5 6
[2,] 7 8 9 10 11
[3,] 12 13 14 15 16
[, 1] [, 2] [, 3] [, 4] [, 5]
[1,] 2 3 4 5 6
[2,] 7 8 9 10 11
[3,] 12 13 14 15 16
>
3. VECTOR:
#create a vector
Sunil<-c ("ball","bat","stumps")
Print (sunil)
#vector
v1=11:20
Print (v1)
v2=20:11
Print (v2)
Print (v1+v2)
Print (v3)
OUTPUT
4. ARITHEMATIC OPERATION:
#Arithematic operations
A = c (11, 41, 17, 31)
B = c (14, 38, 33, 48)
#Addition
A+B
#substraction
A-B
#multiplication
A*B
#Division
A/B
#Recycling Rule
X = c (10, 20, 30)
Z = c (1, 2, 3, 4, 5, 6, 7, 8, 9)
X+Z
A = c ()
OUTPUT
> #Addition
> A+B
[1] 25 79 50 79
> #substraction
> A-B
> #multiplication
> A*B
> #Division
> A/B
> Z = c (1, 2, 3, 4, 5, 6, 7, 8, 9)
> X+Z
[1] 11 22 33 14 25 36 17 28 39
> A = c ()
>
5. ADDITION,SUBSTRACTION,MULTIPLCATION AND DIVISION OF MATRIX
#Addition of matrix
A=matrix(c (11, 13, 15, 17, 19, 15), nrow = 2, ncol = 3)
Print (A)
B=matrix(c (22, 24, 26, 28, 24, 22), nrow = 2, ncol = 3)
Print (B)
#Add the matrix
Result<-A+B
Print (result)
#substraction of matrix
Result<-A-B
Print (result)
#multiplication of matrix
Result<-A*B
Print (result)
#Division of matrix
Result<-A/B
Print (result)
OUTPUT
6. STRING:
OUTPUT
> #to get the length of a text string
> str= "sunil"
> nc=nchar (str)
> print (nc)
[1] 5
OUTPUT
OUTPUT
> print(c)
,, 1
[, 1] [, 2]
[1,] "Black" "white"
,, 2
[, 1] [, 2]
[1,] "Black" "white"
,, 3
[, 1] [, 2]
[1,] "Black" "white"
> print(c)
[, 1] [, 2] [, 3] [, 4] [, 5]
[1,] 2 2 2 2 2
[2,] 3 3 3 3 3
[3,] 2 2 2 2 2
[4,] 3 3 3 3 3