CSE 3020 Data Visualization (L13+L14) Lab Assessment - 1: For All The Questions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

CSE 3020 Data Visualization (L13+L14)

Lab Assessment - 1

For all the questions:


1. Syntax
• All Syntax must include your name in comment
2. Output Screenshot are required
• All output Screenshot must include your name
3. Without your name, assessment will not be evaluated
4. Deadline for submission: 09-Feb-2022
5. Assignment submission: VTOP
6. Weightage: 10
7. Roll No. and Name should be in the Header of file.
8. Be creative and Be Genuine.
CSE3020 Data Visualization
Assessment I-Basic R Programming

1. Create the following sequences using the commands rep and seq.

a) 123456789

b) "m" "w" "m" "w" "m" "w" "m" "w" "m" "w"

c) 123412341234

d) 444333222111

e) 122333444455555

f) 1 1 3 3 5 5 7 7 9 9 11 11

2.

a. Try the commands sqrt(16), 16^0.5. Compute 43 . 2.

b. Try the commands log10(1000), log(1000), exp(log(1000)).

c. Try the command log2(64). Make sure you understand different


logarithmic functions.

d. Try the command ?log.

e. Try the commands pi, round(pi), round(pi, digits=4), and


trunc(pi).

f. The sine and cosine functions are implemented in sin and cos.
Calculate sin(π), cos(π), sin(π/2), cos(π/2)

3. Try the following and record the outputs and describe the effect of the
commands

a. > 2 + 3
b. > x = 2 + 3

>x

c. > y = c(2, 3)

>y

> sum(y)

d. > v = c(5: 40)

>v

e. > length(v)

f. > v[10]

g. > v[-10]

h. > z = c(3:10)

>z + 5

i. > 2 * z

j. > w = c(6.9, 2.7, 0, -11.3, 5.5, -7.8, 4.1, 3.2)

>w + z

k. > w * z

l. > w / z

m. > w^2
Programs based on R Basics

Try the following commands and record the output along with the effects of the
commands

1. > 4+6

2. Object Assignment:

>x<-6

>y<-4

>z<-x+y

>z

3. >ls()

4.> sqrt(16)

5. >rm(x,y)

6. > z<-c(5,9,1,0)

2.
i. > x<-c(5,9)

a. y<-c(1,0)

b. z<-c(x,y)

ii. >x<-1:10

iii. >seq(1,9,by=2)

iv. >seq(8,20,length=6)
v. >x<-seq(1,10)

vi. >rep(0,100)

vii. > rep(1:3,6)

Viii > rep(1:3,c(6,6,6))

iX >rep(1:3,rep(6,3))

3.

>x<-c(6,8,9)

y<-c(1,2,4)

(i) >x+y

(ii) > x*y

(iii) >x<-c(6,8,9)

(iv) > x+2


4. Define x<-c(4,2,6) y<-c(1,0,-1)

Decide what the result will be of the following:

[1] length(x)

[2] sum(x)

[3] sum(x^2)

[4] x+y

[5] x*y

[6] x-2

[7] x^2

5. Decide what the following sequences are and use R to check your answers:

(i) 7:11

(ii) seq(2,9)

(iii) seq(4,10,by=2)

(iv) seq(3,30,length=10)

(v) seq(6,-4,by=-2)

6. Determine what the result will be of the following R expressions, and then use
R to check you are right:

[1] rep(2,4)
[2] rep(c(1,2),4)

[3] rep(c(1,2),c(4,4))

[4] rep(1:4,4)

[5] rep(1:4,rep(3,4))
6. Consider

> x<-

c(7.5,8.2,3.1,5.6,8.2,9.3,6.5,7.0,9.3,1.2,14.5,6.2)

Find out the following:

> mean(x)

> var(x)

> summary(x)

> x[1:6]

> x[7:12]

> summary(x[1:6])

7. If x<- c(5,9,2,3,4,6,7,0,8,12,2,9) decide what each of the following is and use R to


check your answers:

1. x[2]

2. x[2:4]

3. x[c(2,3,6)] 5

4. x[c(1:5,10:12)]

5. x[-(10:12)]
Matrices

Try the following commands

1. x<-c(5,7,9)
y<-c(6,3,4)
z<-
cbind(x,y) z

2. dim(z)

3. rbind(z,z)

4. z<-matrix(c(5,7,9,6,3,4),nrow=3)

5. z<-matrix(c(5,7,9,6,3,4),ncol=3)

6. z<-matrix(c(5,7,9,6,3,4),nr=3,byrow=T)

7. z<-matrix(c(5,7,9,6,3,4),nr=3,byrow=F)

8. y<-matrix(c(1,3,0,9,5,-1),nrow=3,byrow=T)

9. y+z

10. y*z

11. x<-matrix(c(3,4,-2,6),nrow=2,byrow=T)

12. y%*%x

13. t(z)
14. solve(x) inverse of the matrix
15. Extract sub-components of matrices

a. z[1,1]

b. z[c(2,3),2]

c. z[,2]

d. z[1:2,]
2.

You might also like