CSE 3020 Data Visualization (L13+L14) Lab Assessment - 1: For All The Questions
CSE 3020 Data Visualization (L13+L14) Lab Assessment - 1: For All The Questions
CSE 3020 Data Visualization (L13+L14) Lab Assessment - 1: For All The Questions
Lab Assessment - 1
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.
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)
>v
e. > length(v)
f. > v[10]
g. > v[-10]
h. > z = c(3:10)
>z + 5
i. > 2 * z
>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)
iX >rep(1:3,rep(6,3))
3.
>x<-c(6,8,9)
y<-c(1,2,4)
(i) >x+y
(iii) >x<-c(6,8,9)
[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)
> mean(x)
> var(x)
> summary(x)
> x[1:6]
> x[7:12]
> summary(x[1:6])
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
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.