You are on page 1of 6

ASSIGNMENT NO :-1

> #Q1

> marks=c(15,27,30,12,29,09,35,25,28,16);marks

[1] 15 27 30 12 29 9 35 25 28 16

> marksmt25=marks[marks>25];marksmt25

[1] 27 30 29 35 28

********************************************************************

> # Q2

> seq(1,39,2)

[1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39

*********************************************************************

> #Q3

> rep(5,12)

[1] 5 5 5 5 5 5 5 5 5 5 5 5

********************************************************************

> #Q4

> x=c(2,5,3,7,5,8,4,2,7)

>x

[1] 2 5 3 7 5 8 4 2 7

> y=c(2,4,7);y

[1] 2 4 7

> x+y

[1] 4 9 10 9 9 15 6 6 14

> x/y

[1] 1.0000000 1.2500000 0.4285714 3.5000000 1.2500000 1.1428571 2.0000000

[8] 0.5000000 1.0000000

> x*y

[1] 4 20 21 14 20 56 8 8 49

> add=c(x,y);add
[1] 2 5 3 7 5 8 4 2 7 2 4 7

> end=c(y,4,3,2,5,8,9,12,15,17);end

[1] 2 4 7 4 3 2 5 8 9 12 15 17

> z=sum(x,y);z

[1] 56

************************************************************************

> #Q5

> x=c(1,5,2,3,7,8,6);x

[1] 1 5 2 3 7 8 6

> y=x^2;y

[1] 1 25 4 9 49 64 36

> z=log10(x);z

[1] 0.0000000 0.6989700 0.3010300 0.4771213 0.8450980 0.9030900 0.7781513

> w=1/x;w

[1] 1.0000000 0.2000000 0.5000000 0.3333333 0.1428571 0.1250000 0.1666667

*********************************************************************

> #Q6

> age=c(22,27,31,41,30,25,19,20,23,35);age

[1] 22 27 31 41 30 25 19 20 23 35

> age[4]

[1] 41

> agegt30=age[age>30];agegt30

[1] 31 41 35

> length(age)

[1] 10

> age[c(8,9,10)]

[1] 20 23 35

> age[-c(5,7)]

[1] 22 27 31 41 25 20 23 35

> age=c(age[age>20 & age<25]);age


[1] 22 23

**************************************************************

> #Q7

> h=c(140,137,150,147,139,140,150,132,138,140);h

[1] 140 137 150 147 139 140 150 132 138 140

> w=c(55,57,59,62,61,60,60,58,59,57);w

[1] 55 57 59 62 61 60 60 58 59 57

> d1=data.frame("hight"=h,"weight"=w);d1

hight weight

1 140 55

2 137 57

3 150 59

4 147 62

5 139 61

6 140 60

7 150 60

8 132 58

9 138 59

10 140 57

> hgt145=h[h>145];hgt145

[1] 150 147 150

> wgt55=w[w>55];wgt55

[1] 57 59 62 61 60 60 58 59 57

> d2=subset(d1,h>145 & w>60);d2

hight weight

4 147 62

*********************************************************************************

> #Q8

> price=c(10,15,20,42,50,60);price

[1] 10 15 20 42 50 60

> quantity=c(4,20,15,10,16,8);quantity
[1] 4 20 15 10 16 8

> d1=data.frame("price"=price,"quantity"=quantity);d1

price quantity

1 10 4

2 15 20

3 20 15

4 42 10

5 50 16

6 60 8

> d1=transform(d1,"P"=price*quantity);d1

price quantity P

1 10 4 40

2 15 20 300

3 20 15 300

4 42 10 420

5 50 16 800

6 60 8 480

>

*************************************************************************

> #Q9

> age<-c(56,42,72,36,63,47,55,49,38,42);age

[1] 56 42 72 36 63 47 55 49 38 42

> blood<-c(147,125,160,118,149,128,150,145,115,140);blood

[1] 147 125 160 118 149 128 150 145 115 140

> plot(age,blood,xlim=c(35,75),ylim=c(110,165),xlab="age in year",ylab="blood


pressure",main="scatter diagram")

> abline(lm(blood~age),col="red")

> d=data.frame(age,blood);d

age blood

1 56 147

2 42 125
3 72 160

4 36 118

5 63 149

6 47 128

7 55 150

8 49 145

9 38 115

10 42 140

> r=cor(d);r

age blood

age 1.0000000 0.8941748

blood 0.8941748 1.0000000

> m=matrix(r)

> a=m[1,1];a

[1] 1

> b=m[2,1];b

[1] 0.8941748

*******************************************************************************

> #Q-10

> x=c(4,4,12,18,9,6,12,3,6,15,7,3,55,1,10,13,5,7,1,23,9);x

[1] 4 4 12 18 9 6 12 3 6 15 7 3 55 1 10 13 5 7 1 23 9

> boxplot(x,ylab="patient")

> f=fivenum(x);f

[1] 1 4 7 12 55
> text(rep(1.35,6),f,labels=c("minimum","lower quartile","madian","upper quartile","maximum"))

You might also like