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

> #Question:9

> grass2=read.csv(file.choose())
> grass2
rich graze
1 12 mow
2 15 mow
3 17 mow
4 11 mow
5 15 mow
6 8 unmow
7 9 unmow
8 7 unmow
9 9 unmow
> grass2matrix=as.matrix(grass2)
> grass2matrix
rich graze
[1,] "12" "mow"
[2,] "15" "mow"
[3,] "17" "mow"
[4,] "11" "mow"
[5,] "15" "mow"
[6,] " 8" "unmow"
[7,] " 9" "unmow"
[8,] " 7" "unmow"
[9,] " 9" "unmow"
> grass2dataframe=as.data.frame(grass2matrix)
> grass2dataframe
rich graze
1 12 mow
2 15 mow
3 17 mow
4 11 mow
5 15 mow
6 8 unmow
7 9 unmow
8 7 unmow
9 9 unmow
> #hence , we again created a data frame from a matrix
> mf=read.csv(file.choose())
> mf
grass heath arable
1 8 20 49
2 9 19 48
3 10 28 47
4 9 22 46
5 9 23 47
6 8 21 45
7 7 20 47
8 6 19 48
9 8 18 48
10 5 16 49
11 4 14 50
12 8 24 51
13 9 22 56
> list=as.list(mf)
> list
$grass
[1] 8 9 10 9 9 8 7 6 8 5 4 8 9

$heath
[1] 20 19 28 22 23 21 20 19 18 16 14 24 22

$arable
[1] 49 48 47 46 47 45 47 48 48 49 50 51 56

> list2=as.list(grass2matrix)
> list2
[[1]]
[1] "12"

[[2]]
[1] "15"

[[3]]
[1] "17"

[[4]]
[1] "11"

[[5]]
[1] "15"

[[6]]
[1] " 8"
[[7]]
[1] " 9"

[[8]]
[1] " 7"

[[9]]
[1] " 9"

[[10]]
[1] "mow"

[[11]]
[1] "mow"

[[12]]
[1] "mow"

[[13]]
[1] "mow"

[[14]]
[1] "mow"

[[15]]
[1] "unmow"
[[16]]
[1] "unmow"

[[17]]
[1] "unmow"

[[18]]
[1] "unmow"

> a.list=as.list(grass2matrix)
> a.list
[[1]]
[1] "12"

[[2]]
[1] "15"

[[3]]
[1] "17"

[[4]]
[1] "11"

[[5]]
[1] "15"

[[6]]
[1] " 8"
[[7]]
[1] " 9"

[[8]]
[1] " 7"

[[9]]
[1] " 9"

[[10]]
[1] "mow"

[[11]]
[1] "mow"

[[12]]
[1] "mow"

[[13]]
[1] "mow"

[[14]]
[1] "mow"

[[15]]
[1] "unmow"
[[16]]
[1] "unmow"

[[17]]
[1] "unmow"

[[18]]
[1] "unmow"

> matrix=as.matrix(a.list)
> matrix
[,1]
[1,] "12"
[2,] "15"
[3,] "17"
[4,] "11"
[5,] "15"
[6,] " 8"
[7,] " 9"
[8,] " 7"
[9,] " 9"
[10,] "mow"
[11,] "mow"
[12,] "mow"
[13,] "mow"
[14,] "mow"
[15,] "unmow"
[16,] "unmow"
[17,] "unmow"
[18,] "unmow"

> #Ques : 10
> table=as.table(data2)
> table
ABCDEFGHIJKLMNOP
3575326856945734
> stem(data2)

The decimal point is at the |

2 | 0000
4 | 000000
6 | 0000
8 | 00

> stem(data2,scale=2)

The decimal point is at the |

2|0
3 | 000
4 | 00
5 | 0000
6 | 00
7 | 00
8|0
9|0

> hist(data2,main='histogram of
data2',xlab='abcd',ylab='efgh',xlim=c(1,10),ylim=c(0,0.5),col='red',border='black',breaks=c(2
,4,5,6,9))

> #Ques : 11
>fw
abund flow
1 9 2
2 25 3
3 15 5
4 2 9
5 14 14
6 25 24
7 24 29
8 47 34
> rm(fw)
> fw=read.csv(file.choose())
> fw
X count speed
1 taw 9 2
2 torridge 25 3
3 ouse 15 5
4 exe 2 9
5 lyn 14 14
6 brook 25 24
7 ditch 24 29
8 fal 47 34

> boxplot(fw$speed)
> boxplot(fw$speed,fw$count)
> boxplot(fw$speed,fw$count,names=c('speed','count'))
> title(xlab='variable',ylab='value')
>boxplot(fw$speed,fw$count,names=c('speed','count'),range=0,main='title',xlab='var
iable',ylab='value',col='red')

>
boxplot(fw$speed,fw$count,names=c('speed','count'),range=0,main='title',xlab='variable',yl
ab='value',col='red',horizontal=TRUE)
> #Question : 12
> fw
X count speed
1 taw 9 2
2 torridge 25 3
3 ouse 15 5
4 exe 2 9
5 lyn 14 14
6 brook 25 24
7 ditch 24 29
8 fal 47 34
> plot(count~speed,data=fw,xlab='speed m/s',ylab='count of
Mayfly',pch=18,cex=2,col='green',xlim=c(0,50),ylim=c(0,50))
> abline(lm(count~speed,data=fw),lty='dotted',lwd=2,col='red')

> #Ques : 13
> women=read.csv(file.choose())
> women
height weight
1 58 115
2 59 117
3 60 120
4 61 123
5 62 126
6 63 129
7 64 132
8 65 135
9 66 138
10 67 141
11 68 144
12 69 147
13 70 150
14 71 153
15 72 156
> plot(women,pch=19,cex=1.5)
> cars
speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10
7 10 18
8 10 26
9 10 34
10 11 17
11 11 28
12 12 14
13 12 20
14 12 24
15 12 28
16 13 26
17 13 34
18 13 34
19 13 46
20 14 26
21 14 36
22 14 60
23 14 80
24 15 20
25 15 26
26 15 54
27 16 32
28 16 40
29 17 32
30 17 40
31 17 50
32 18 42
33 18 56
34 18 76
35 18 84
36 19 36
37 19 46
38 19 68
39 20 32
40 20 48
41 20 52
42 20 56
43 20 64
44 22 66
45 23 54
46 24 70
47 24 92
48 24 93
49 24 120
50 25 85

> plot(speed~dist,data=cars)

> abline(lm(dist ~ speed, data = cars), lwd = 2)


>mf=read.csv(file.choose())
> mf
length speed algae no3 BOD
1 20 12 40 2.25 200
2 21 12 45 2.15 180
3 22 14 40 2.10 135
4 23 13 44 2.20 120
5 21 14 40 2.25 110
6 20 13 45 2.15 200
7 21 14 40 2.10 180
8 22 15 44 2.20 135
9 23 16 40 2.25 120
10 21 20 45 2.15 110
11 20 31 40 2.10 200
12 21 21 44 2.20 180
13 22 12 40 2.25 135
14 23 12 45 2.15 120
15 21 13 40 2.10 110
16 20 13 44 2.20 200
17 21 13 40 2.25 180
18 22 13 45 2.15 135
19 23 31 40 2.10 120
20 21 13 44 2.20 110
> plot(length ~ algae, data = mf)

> abline(lm(length ~ algae, data = mf), lty = 2)


> #Ques : 14
> fw
X count speed
1 taw 9 2
2 torridge 25 3
3 ouse 15 5
4 exe 2 9
5 lyn 14 14
6 brook 25 24
7 ditch 24 29
8 fal 47 34
> plot(fw)
> pairs(~length + speed + no3, data = mf)
> #Ques : 15
> Nile
Time Series:
Start = 1871
End = 1970
Frequency = 1
[1] 1120 1160 963 1210 1160 1160 813 1230 1370 1140 995 935 1110 994 1020
[16] 960 1180 799 958 1140 1100 1210 1150 1250 1260 1220 1030 1100 774 840
[31] 874 694 940 833 701 916 692 1020 1050 969 831 726 456 824 702
[46] 1120 1100 832 764 821 768 845 864 862 698 845 744 796 1040 759
[61] 781 865 845 944 984 897 822 1010 771 676 649 846 812 742 801
[76] 1040 860 874 848 890 744 749 838 1050 918 986 797 923 975 815
[91] 1020 906 901 1170 912 746 919 718 714 740
> plot(Nile, type = 'l')
> rainfall=read.csv(file.choose())
> rainfall
rain month
1 3 jan
2 5 feb
3 7 mar
4 5 apr
5 3 may
6 2 jun
7 6 jul
8 8 aug
9 5 sep
10 6 oct
11 9 nov
12 8 dec
> plot(rainfall$rain,type='b')
> plot(rainfall$rain,type='b',axes = FALSE, xlab = 'Month', ylab = 'Rainfall cm')
> month = c('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep','oct','nov','dec')
> axis(side = 1, at = 1: length(rainfall$rain), labels = month)
> axis(side = 2)
> box()
> #Ques :16
> data11=c(3,5,7,5,3,2,6,8,5,6,9,8)
> data8=c('jan','feb','apr','may','jun','jul','aug','sept','oct','nov','dec')
> pc=c('red','blue','green','gray40','gray60','gray90')
> pie(data11,labels=data8,col=pc,clockwise=TRUE,init.angle=180)
> dotchart(data11,labels=data8)

>
>#END END END END END END END END END END END END END END END END END END.

You might also like