Jatiya Kabi Kazi Nazrul Islam University
Department of Statistics
B. Sc. 2nd Year 2nd Semester Mid-I
Course Code: STAT-217, Course Title: Programming with R and Python
Times: 45 Minutes Full Marks: 10
a) If the following commands were type into the console window of R, write down the response 3
if any,
(i) if x<-c(1, 2, 3, 10, 8), then find sort(x, descending=T)
(ii) if x=5, y=3, then find (x/2+5)%%y, x%/%y and sqrt(y^2+2*x-4)
(iii) if x<-c(1, 2, NA, 3, 5, 8, 13)
x[[Link](x)]<-0
y<-x[-1]-x[-length(x)]
b) Define matrix in R with example. Distinguish between data frame and list. When to use the 3
function which(), rbind (), and cbind in R?
c) When do you use and write down the syntax of if statement, ifelse statement, and for loop 4
statement? Briefly describe different components of function in R. Write a R function to
calculate the variance of a random variable.
Jatiya Kabi Kazi Nazrul Islam University
Department of Statistics
B. Sc. 2nd Year 2nd Semester Mid-I
Course Code: STAT-217, Course Title: Programming with R and Python
Times: 45 Minutes Full Marks: 10
a) If the following commands were type into the console window of R, write down the 3
response if any,
(iv) if x<-c(1, 2, 3, 10, 8), then find sort(x, descending=T)
(v) if x=5, y=3, then find (x/2+5)%%y, x%/%y and sqrt(y^2+2*x-4)
(vi) if x<-c(1, 2, NA, 3, 5, 8, 13)
x[[Link](x)]<-0
y<-x[-1]-x[-length(x)]
b) Define matrix in R with example. Distinguish between data frame and list. When to use the 3
function which(), rbind (), and cbind in R?
c) When do you use and write down the syntax of if statement, ifelse statement, and for loop 4
statement? Briefly describe different components of function in R. Write a R function to
calculate the variance of a random variable.