0% found this document useful (0 votes)
17 views

R Program Record 2023

This document contains 8 experiments demonstrating basic operations in R such as arithmetic, variable assignment, data types, creating vectors and matrices, selecting elements, and performing operations on matrices. Each experiment includes the aim, program code, and output results. The experiments progress from basic arithmetic to more advanced operations with vectors and matrices.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

R Program Record 2023

This document contains 8 experiments demonstrating basic operations in R such as arithmetic, variable assignment, data types, creating vectors and matrices, selecting elements, and performing operations on matrices. Each experiment includes the aim, program code, and output results. The experiments progress from basic arithmetic to more advanced operations with vectors and matrices.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

S.

Marks Remarks
No Date Title Page Awarded
no

1 To Illustrate basic 01
arithmetic in R

2 To Illustrate Variable 2-3


Assignment in R

3 To Illustrate data types in R 4-5

4 To illustrate creating and 6


naming vectors in R’

5 To create a matrix and 7


naming matrix in R

6 To illustrate add column 8


and add a row in matrix in
R
7 To illustrate selection of 9
elements in matrices in R

8 To illustrate performing 10-11


athematic of matrices
PAGE NO : 01

EXPERIMENT-1

AIM :

To Illustrate basic arithmetic in R

PROGRAMME:

a=4
b=2
add=a+b
sub=a-b
div=a/b
mul=a*b
int_div=a%/%b
modulus=a%%b
exponent=a^b
print(paste(“addition:”,add))
print(paste(“subtraction:”,sub))
print(paste(“multiplication:”,mul))
print(paste(“division:”,int_div))
print(paste(“modulus:”,modulus))
print(paste(“a power b:”,exponent))

OUTPUT:

[1]”addition:6”
[1]“subtraction:2”
[1]“division:2”
[1]“multiplication:8”
[1]“integer division:2”
[1]“modulus:0”
PAGE NO : 02
EXPERIMENT - 2
AIM:

To Illustrate Variable Assignment in R

PROGRAMME:

#assignment of variables…
#their are five types of assignment operators
.#1.left assignment
#2.left assignment(“=”not recommended)
#3.right assignment=>
#4.left lexicographic assignment(advanced)
#5.right lexicographic assignment(advanced)
X<-3
Y=5
Z->z
A<<-1
2->>b
Print(x)
Print(y)
Print(z)
Print(a)
Print(b)

OUTPUT:

Print(x)

[1] 3

Print(y)

[1]5

Print(z)

[1]7
Print(a)
PAGE NO : 03

[1]1

Print(b)

[1]2
PAGE NO : 04
EXPERIMENT - 3
AIM:

To Illustrate data types in R

PROGRAMME:

# types of data types in R….

X<-123L#integer

Print(class(x))

X<-TRUE

Print(class(x))

X<-63

Print(class(x))

X<-63.5

Print(class(x))

X<-3+2;

Print(class(x))

X<-”hello”

Print(class(x))

OUTPUT:

[1] ”integer”

[1] ”logical”

[1] “numerical”
PAGE NO : 05

[1] “complex”

[1] “character”
PAGE NO : 06
EXPERIMENT - 4
AIM :

to illustrate creating and naming vectors in R’

PROGRAM:

#creating a vector
Vec<-c(1:10)
Vec
Vec<-c(1,2,3,4,5)
Vec
Vec<-c(TRUE,FALSE)
Vec

OUTPUT :

Creatng a vector
> vec <_c(1:10)
>vec
[1] 1 2 3 4 5 6 7 8 9 10
>vec <-c(1,2,3,4,5)
>vec
[1] 1 2 3 4 5
>vec <-c(TRUE,FALSE)
>vec
[1] TRUE,FALSE
PAGE NO : 07
EXPERIMENT - 5

AIM :

to create a matrix and naming matrix in R

PROGRAM :

# creating and assigning matrices in R


A = matrix(c(1,2,3,4,5,6,7,8,9),3,3,TRUE)
Print(A)
#constant matrix
A = matrix yh
Print(A)
#diagonal matrix
A = matrix(diag(1,2,3),3,3)
Print(A)
#identity matrix
A = matrix(diag(1),3,3)
Print(A)

OUTPUT :

1 2 3
4 5 6
7 8 9

2 2 2
2 2 2
2 2 2

1 1 1
0 0 0
0 0 0

1 1 1
1 1 1
1 1 1
PAGE NO : 08

EXPERIMENT – 6

AIM :

to illustrate add column and add a row in matrix in R

PROGRAM :

# adding element to the rows and columns

M<-matrix(c(1:9),3,3,TRUE)

Print(M)

B<-rbind(M,c(2,4,5))

Print(c)

OUTPUT :

1 2 3
4 5 6
7 8 9

1 2 3
4 5 6
7 8 9
10 11 12

1 2 3 2
4 5 6 4
7 8 9 7
PAGE NO : 09
EXPERIMENT - 7

AIM :

to illustrate selection of elements in matrices in R

PROGRAM :

M <-matrix(c(1:9),3,3,TRUE)

M[1,2]

M[2,3]

M[,2]

M[2,]

OUTPUT :

> M[1,2]
[1] 1
> M[2,3]
[1] 1
> M[,2]
[1] 1 1 1
> M[2,]
[1] 1 1 1
PAGE NO : 10
EXPERIMENT - 8

AIM :

to illustrate performing athematic of matrices

PROGRAM :

A <-matrix(c(1:4),2,2,TRUE)

B <-matrix(c(5:8),2,2,TRUE)

Print(A+B)

Print(A-B)

Priint(A*B)

Print(B/A)

OUTPUT :

> (A+B)
[,1] [,2]

[1,] 6 8

[2,] 10 12

> (A-B)
-4 -4
-4 -4

> (A*B)
PAGE NO : 11
5 12
21 32

> (B/A)
5.00000 3

2.33333 2

You might also like