You are on page 1of 9

BUSINESS ANALYTICS

ASSIGNMENT-2

DATE: 18/07/2020

GROUP MEMBERS: -
BINISH SIDDIQUI (19021141032)
NIKHIL MALHOTRA (19021141074)
Raveen K Pai (19021141084)
Arghya Chakraborty (19021141024)
SYNTAX
mtcars
dim(mtcars)
help("mtcars")
table(mtcars$cyl)
library(dplyr)
x=mtcars%>%count(cyl)
x
names(x)=c("cyl","freq")
x
x$RF=(x$freq)/32
x
x$PerRF=((x$freq)/32)*100
x
x$CumF=cumsum(x$freq)
x
y=mtcars%>%count(cyl,vs)
y
y=mtcars%>%count(cyl,vs,hp)
y
y=mtcars%>%count(cyl,hp)
y
#cross tabulation, gmodels
library(gmodels)
CrossTable(mtcars$cyl,mtcars$vs)
OUTPUT

> mtcars

> dim(mtcars)
[1] 32 11
> help("mtcars")
> library(dplyr)

Attaching package: ‘dplyr’


> table(mtcars$cyl)

4 6 8
11 7 14

> library(dplyr)
> x=mtcars%>%count(cyl)
>x
cyl n
1 4 11
2 6 7
3 8 14
> names(x)=c("cyl","freq")
>x
cyl freq
1 4 11
2 6 7
3 8 14
> x$RF=(x$freq)/32
>x
cyl freq RF
1 4 11 0.34375
2 6 7 0.21875
3 8 14 0.43750
> x$PerRF=((x$freq)/32)*100
>x

cyl freq RF PerRF


1 4 11 0.34375 34.375
2 6 7 0.21875 21.875
3 8 14 0.43750 43.750
> x$CumF=cumsum(x$freq)
>x
cyl freq RF PerRF CumF
1 4 11 0.34375 34.375 11
2 6 7 0.21875 21.875 18
3 8 14 0.43750 43.750 32
> y=mtcars%>%count(cyl,vs)
>y
cyl vs n
1 4 0 1
2 4 1 10
3 6 0 3
4 6 1 4
5 8 0 14
> #cross tabulation
> CrossTable
> CrossTable(mtcars$cyl,mtcars$vs) # gmodels package
> table(mtcars$cyl)
4 6 8
11 7 14

> library(dplyr)
> y=mtcars%>%count(cyl,vs,hp)
>y
cyl vs hp n
1 4 0 91 1
2 4 1 52 1
3 4 1 62 1
4 4 1 65 1
5 4 1 66 2
6 4 1 93 1
7 4 1 95 1
8 4 1 97 1
9 4 1 109 1
10 4 1 113 1
11 6 0 110 2
12 6 0 175 1
13 6 1 105 1
14 6 1 110 1
15 6 1 123 2
16 8 0 150 2
17 8 0 175 2
18 8 0 180 3
19 8 0 205 1
20 8 0 215 1
21 8 0 230 1
22 8 0 245 2
23 8 0 264 1
24 8 0 335 1
> y=mtcars%>%count(cyl,hp)
>y
cyl hp n
1 4 52 1
2 4 62 1
3 4 65 1
4 4 66 2
5 4 91 1
6 4 93 1
7 4 95 1
8 4 97 1
9 4 109 1
10 4 113 1
11 6 105 1
12 6 110 3
13 6 123 2
14 6 175 1
15 8 150 2
16 8 175 2
17 8 180 3
18 8 205 1
19 8 215 1
20 8 230 1
21 8 245 2
22 8 264 1
23 8 335 1
> #cross tabulation, gmodels
> library(gmodels)
> CrossTable(mtcars$cyl,mtcars$vs)

You might also like