R Programming Notes
R Programming Notes
> 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)
2 | 0000
4 | 000000
6 | 0000
8 | 00
> stem(data2,scale=2)
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)
>
>#END END END END END END END END END END END END END END END END END END.