0% found this document useful (0 votes)
100 views3 pages

R Programming - Assignment

The document provides instructions and solutions for 3 problems in R programming. Problem 1 involves creating vectors a and b using sequences, multiplying them to create vector d, and selecting subsets of d. Problem 2 involves computing statistics (sum, median, standard deviation) of vector d. Problem 3 involves matrix multiplication of matrices a and b.

Uploaded by

Raghav V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views3 pages

R Programming - Assignment

The document provides instructions and solutions for 3 problems in R programming. Problem 1 involves creating vectors a and b using sequences, multiplying them to create vector d, and selecting subsets of d. Problem 2 involves computing statistics (sum, median, standard deviation) of vector d. Problem 3 involves matrix multiplication of matrices a and b.

Uploaded by

Raghav V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

R PROGRAMMING-ASSIGNMENT-1 RAGHAV V

22MBA10001

Problem 2: Create the following vectors in R.

a = (5, 10, 15, 20, ..., 160)

b = (87, 86, 85, ..., 56)

Use vector arithmetic to multiply these vectors and call the result d. Select subsets of d to

identify the following.

(a) What are the 19 th , 20 th , and 21 st elements of d?

(b) What are all of the elements of d which are less than 2000?

(c) How many elements of d are greater than 6000?

Solution:

a=seq(5,160,by=5)

b=seq(87,56,by=-1)

multiply these vectors

d=a*b

print(d)

(a) d[19:21]
(b) d[d<2000]
(c) length(d[d>6000])
Output:

Problem 3: Using d from problem 2, use R to compute the

following statistics of d:

(a) sum

(b) median

(c) standard deviation

Solution code:

sum(d)

median(d)

sd(d)

Output:
Solution Code:

a=matrix(c(7,2,9,4,12,13),ncol = 3)

b=matrix(c(1,2,3,7,8,9,12,13,14,19,20,21),nrow = 3)

#matrix multiplication

c=a%*%b

Output:

You might also like