Professional Documents
Culture Documents
D.A Lab Assignment-03: Input
D.A Lab Assignment-03: Input
D.A Lab Assignment-03: Input
A LAB ASSIGNMENT-03
{NAME:RUDRASISH MISHRA} | {SECTION:IT-8} | {ROLL NO:1906649}
getRoot_649( c(4,-4,9,-16,121))
OUTPUT:
Q2. Write an R-script to initialise two vectors and then check if both
vectors are equal or not?
SOLUTION:
INPUT:
vec1_649<-c(1,0,0,1,1,0,0,1,1,1,0,0,0)
vec2_649<-c(0,0,1,1,1,0,0,1,1,0,1,0,1)
print(vec1_649)
print(vec2_649)
c_649<-vec1_649 & vec2_649
print(c_649)
OUTPUT:
OUTPUT:
Q5. Write an R-script to initialise two vectors and then evaluate the 1st
vector raised to the power of the 2nd vector.
SOLUTION:
INPUT:
X_649 <- c(5, 2, 5, 1, 51, 2)
Y_649 <- c(7, 9, 1, 5, 2, 1)
OUTPUT:
Q6. Write an R-script to initialise a vector and then find out minimum
value and maximum value, also evaluate the sum of all the elements.
SOLUTION:
INPUT:
OUTPUT:
Q7. Write an R-script to initialise a vector and then search a specific
element from that vector.
SOLUTION:
INPUT:
OUTPUT:
Q8. Write an R-script to create a list with different types of data set.
Now display each data set separately according to the data type.
SOLUTION:
INPUT:
{
vec_649 <- 1:5
mat_649 <- matrix(c(1:9, ncol = 5))
OUTPUT:
Q9. Write an R-script to create a list having a vector, matrix and a list.
Now display only the 2nd data set of the list.
SOLUTION:
INPUT:
{
vec_649 <- c(1,2,4,8,10)
m_649 <- matrix(c(3:14),nrow = 4,byrow = TRUE)
list1_649 <- list("Red","Green",c(21,32,11),TRUE,51.23)
list_data_649 <- list(vec_649,m_649,list1_649)
print(list_data_649(2))
}
OUTPUT:
Q10. Write an R-script to add a new data set to the previous list and also
remove the 2nd data set from that list.
SOLUTION:
INPUT:
{
list1_649 <- list(c("ALPHA","BETA"),c(21,32,11),
matrix(c(3,9,5,1,-2,8),nrow = 2))
print(list1_649)
list1_649[4] <- "New Element"
print(list1_649[4])
list1_649[2] <- NULL
print(list1_649)
}
OUTPUT:
Q11. Write an R-script to create two lists- one contains the integers from
1 to 5 and another contains the name of 5 months. Now merge two lists
and display that.
SOLUTION:
INPUT:
{
lits1_649 <- list(1,2,3,4,5)
list2_649 <-
list("January","feburary","March","April","May")
merged.list_649 <- c(list1_649,list2_649)
print(merged.list_649)
}
OUTPUT:
Q12. Write an R-script to create a 4*3 matrix. Now display the elements
of row1, row3 and column2 of that matrix.
SOLUTION:
INPUT:
OUTPUT:
Q13. Write an R-script to create two matrices and then perform addition,
subtraction, multiplication and division of them.
SOLUTION:
INPUT:
Q14. Write an R-script to create a 3*3 matrix and update that matrix by
adding 4 to each and every element, also display the updated matrix.
SOLUTION:
INPUT:
{
m_649 <- matrix(c(3:12),nrow = 3,ncol=3, byrow = TRUE)
m_649 <- m_649[1:3,1:3] + 4
print(m_649)
}
OUTPUT:
OUTPUT:
Q16. Write an R-script to check if the given matrix is a symmetric matrix
or not?
SOLUTION:
INPUT:
{
x1_649 <- matrix(c(1:9),nrow = 3,ncol = 3)
cat("The given matrix is
symmetric",isSymmetric(x1_649),"\n")
x2_649 <- diag(3)
print(x2_649)
cat("The above matrix is
symmetric",isSymmetric(x2_649))
}
OUTPUT:
Q17. Write an R-script to create a matrix and evaluate the sum of the
elements row wise.
SOLUTION:
INPUT:
x_649 <- matrix(rep(2:10), 3, 3)
print(x_649)
rowSum_649 <-rowSums(x_649)
print("Sum of the elements row wise is :",rowSum_649)
OUTPUT:
OUTPUT:
Q19. Write an R-script to create an array having 3 dimensions. Now
calculate the sum of the rows across all the matrices.
SOLUTION:
INPUT:
{
vec1_649 <- c(5,9,3)
vec2_649 <- c(4,8,1,13,14,19)
column.names_649 <- c("c1","c2","c3")
row.names_649 <- c("r1","r2","r3")
matrix.names_649 <- c("M1","M2","M3")
OUTPUT:
OUTPUT:
Q21. The diag function has several uses, one of which is to take a vector
as its input and create a square matrix with that vector on the diagonal.
Create a 21-by-21 matrix with the sequence 10 to 0 to 11 (i.e., 11, 10, … , 1,
0, 1, …, 11).
SOLUTION:
INPUT:
{
vec_649 <- c(10:0,0:11)
m_649 <- diag(vec_649,21,21)
print(m_649)
}
OUTPUT: