You are on page 1of 6

Singh Pravin MBA20207

Problem 1
> P <- 27*(38-17)
>P
[1] 567

> P2 <- 14^7


> P2
[1] 105413504

> P3 <- (436/12)^0.5


> P3
[1] 6.027714

Problem 2
> p <- c(seq(5,160, by=5))
>p
[1] 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110
[23] 115 120 125 130 135 140 145 150 155 160

> q <- c(87:56)


>q
[1] 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59
[30] 58 57 56

> r = p*q
>r
[1] 435 860 1275 1680 2075 2460 2835 3200 3555 3900 4235 4560 4875 5180 5475 5760
6035
[18] 6300 6555 6800 7035 7260 7475 7680 7875 8060 8235 8400 8555 8700 8835 8960

a) > r[19]
[1] 6555

> r[20]
[1] 6800

> r[21]
[1] 7035
or
> r[19:21]
[1] 6555 6800 7035

b) > r[r<2000]
[1] 435 860 1275 1680
Problem 3
a) > sum(r)
[1] 175120

b) > median(r)
[1] 5897.5

c) > sd(r)
[1] 2608.563

Problem 4
a) > Student <- c('Anusha', 'Ashutosh', 'Abhisehk', 'Priya', 'Pravin', 'Radhhika', 'Rishabh',
'Rishika', 'Esha', 'Pokemon')
> Student
[1] "Anusha" "Ashutosh" "Abhisehk" "Priya" "Pravin" "Radhhika" "Rishabh"
"Rishika"
[9] "Esha" "Pokemon"

b) > Age <- c(30L, 20L, 34L, 21L, 22L, 29L, 45L, 33L, 49L, 19L)
> Age
[1] 30 20 34 21 22 29 45 33 49 19

c) > Student
[1] "Anusha" "Ashutosh" "Abhisehk" "Priya" "Pravin" "Radhhika" "Rishabh"
"Rishika"
[9] "Esha" "Pokemon"

> Age
[1] 30 20 34 21 22 29 45 33 49 19

d) > Student[4]
[1] "Priya"
> Student[7]
[1] "Rishabh"
> Student[10]
[1] "Pokemon"

> Age[4]
[1] 21
> Age[7]
[1] 45
> Age[10]
[1] 19

e) > names(Age) <- Student


> Age
Anusha Ashutosh Abhisehk Priya Pravin Radhhika Rishabh Rishika Esha Pokemon
30 20 34 21 22 29 45 33 49 19

f)
> Subject <- c('Maths', 'English', 'Chemistry', 'Physics', 'History', 'Geography', 'Arts',
'Commerce', 'Social Scudies', 'Law')
> Subject
[1] "Maths" "English" "Chemistry" "Physics" "History"
[6] "Geography" "Arts" "Commerce" "Social Studies" "Law"

> Consolidated = data.frame(Student,Age,Subject)


> Consolidated
Student Age Subject
1 Anusha 30 Maths
2 Ashutosh 20 English
3 Abhisehk 34 Chemistry
4 Priya 21 Physics
5 Pravin 22 History
6 Radhhika 29 Geography
7 Rishabh 45 Arts
8 Rishika 33 Commerce
9 Esha 49 Social Studies
10 Pokemon 19 Law

g) > Student <- c(“Makita”, 23L, “Marketing”)


> rbind(Consolidated, Student)
> Consolidated
Student Age Subject
1 Anusha 30 Maths
2 Ashutosh 20 English
3 Abhisehk 34 Chemistry
4 Priya 21 Physics
5 Pravin 22 History
6 Radhhika 29 Geography
7 Rishabh 45 Arts
8 Rishika 33 Commerce
9 Esha 49 Social Studies
10 Pokemon 19 Law
11 Makita 23 Marketing
Problem 5

> vec <- c(1,2,3)


> char_vec <- c("Hadoop", "Spark", "Flink", "Mahout")
> logic_vec <- c(TRUE, FALSE, TRUE, FALSE)
> char_vec[3]
[1] "Flink
> Sum <- list(vec, char_vec, logic_vec)
> Sum
[[1]]
[1] 1 2 3
[[2]]
[1] "Hadoop" "Spark" "Flink" "Mahout"
[[3]]
[1] TRUE FALSE TRUE FALSE
Problem 6

> who = read.csv("WHO.csv")


> my_sub = > plot(my_sub$e_mort_exc_tbhiv_num,my_sub $e_inc_num,xlab = "Albania
Estimated number of deaths from TB", ylab= "Albania Estimated number of incident
cases" )

> boxplot(my_sub$e_inc_100k_hi, my_sub$e_mort_num_hi, xlab="Albania 1.total number


of incident, 2. Total Mortality")
Problem 7

a) > x <- data.frame("Student" =c("Ron","Jake","Ava","Sophia","Mia"),"Marks" =


c(35,75,45,30,85))
>x
Student Marks
1 Ron 35
2 Jake 75
3 Ava 45
4 Sophia 30
5 Mia 85

> x$Results = ifelse(x$"Marks">30,"Pass","Fail")


>x
Student Marks Results
1 Ron 35 Pass
2 Jake 75 Pass
3 Ava 45 Pass
4 Sophia 30 Fail
5 Mia 85 Pass

b) > mymat <- matrix(nrow=20, ncol=20)


> for(i in 1:dim(mymat)[1])
+ {
+ for(j in 1:dim(mymat)[2])
+ {
+ mymat[i,j] = i*j
+ }}

> mymat[1:10, 1:10]


[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 1 2 3 4 5 6 7 8 9 10
[2,] 2 4 6 8 10 12 14 16 18 20
[3,] 3 6 9 12 15 18 21 24 27 30
[4,] 4 8 12 16 20 24 28 32 36 40
[5,] 5 10 15 20 25 30 35 40 45 50
[6,] 6 12 18 24 30 36 42 48 54 60
[7,] 7 14 21 28 35 42 49 56 63 70
[8,] 8 16 24 32 40 48 56 64 72 80
[9,] 9 18 27 36 45 54 63 72 81 90
[10,] 10 20 30 40 50 60 70 80 90 100

You might also like