52 R Notebook (Lab Assignment 1)

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Lab_Assignment-1

Download an external file(hair_eye_color.csv)


df<-read.csv("D:/VIT/SY/DS/LAB/hair_eye_color.csv")
head(df)

## Person.No. Hair.Color Eye.Color


## 1 1 Blonde Blue
## 2 2 Blonde Blue
## 3 3 Blonde Green
## 4 4 Blonde Brown
## 5 5 Blonde Brown
## 6 6 Blonde Black

summary(df)

## Person.No. Hair.Color Eye.Color


## Min. : 1.00 Length:20 Length:20
## 1st Qu.: 5.75 Class :character Class :character
## Median :10.50 Mode :character Mode :character
## Mean :10.50
## 3rd Qu.:15.25
## Max. :20.00

Q1) How many people have Brown eye color?


nrow(subset(df,df$Eye.Color=="Brown"))

## [1] 10

How many people have Blonde hair?


nrow(subset(df,df$Hair.Color=="Blonde"))

## [1] 6

How many Brown haired people have Black eyes?


nrow(df[df$Hair.Color=="Brown"& df$Eye.Color=="Black",])

## [1] 2

What is the percentage of people with Green eyes?


c<-nrow(subset(df,df$Eye.Color=="Green"))
(c/length(df$Eye.Color))*100

## [1] 10
What percentage of people have red hair and Blue eyes?
nrow(df[df$Hair.Color == "Red" & df$Eye.Color == "Blue", ]) * 100 / nrow(df)

## [1] 5
Q2

df1<read.csv("D:/VIT/SY/DS/LAB/
## 3 Uncovered 1 27
germination.csv")
## 4 Uncovered 1 23
head(df1)
## 5 Uncovered 2 41
#### 6 Uncovered 2
Box water_amt 46
## 1 Uncovered122
germinated
##summary(df1)
2 Uncovered125
## Box water_amt germinated
## Length:48 Min. :1.0 Min. : 0.00
## Class :character 1st Qu.:2.0 1st Qu.:30.00
## Mode :character Median :3.5 Median :48.50
## Mean :3.5 Mean :47.62
## 3rd Qu.:5.0 3rd Qu.:73.00
## Max. :6.0 Max. :84.00

What is the average number of seeds germinated for the uncovered boxes with level of
watering equal to 4?
mean(subset(df1$germinated,df1$Box=="Uncovered" & df1$water_amt==4))

## [1] 78

What is the median value for the data covered boxes?


median(subset(df1$germinated,df1$Box=="Covered"))

## [1] 45

Establish conclusions on the o available data: a. Association of levels of watering with the
number of germinating seeds in case Of covered boxes as well as uncovered boxes.
mean(subset(df1$germinated,df1$Box=="Covered" & df1$water_amt==1))

## [1] 42.75

mean(subset(df1$germinated,df1$Box=="Covered" & df1$water_amt==2))

## [1] 75.25

mean(subset(df1$germinated,df1$Box=="Covered" & df1$water_amt==3))

## [1] 76

mean(subset(df1$germinated,df1$Box=="Covered" & df1$water_amt==4))

## [1] 52
mean(subset(df1$germinated,df1$Box=="Covered" & df1$water_amt==5))

## [1] 37.75

mean(subset(df1$germinated,df1$Box=="Covered" & df1$water_amt==6))

## [1] 0

Germination is increasing from water level 1-3 and decreasing 3-5 and it is 0 at water level
6
mean(subset(df1$germinated,df1$Box=="Uncovered" & df1$water_amt==1))

## [1] 24.25

mean(subset(df1$germinated,df1$Box=="Uncovered" & df1$water_amt==2))

## [1] 46

mean(subset(df1$germinated,df1$Box=="Uncovered" & df1$water_amt==3))

## [1] 66.75

mean(subset(df1$germinated,df1$Box=="Uncovered" & df1$water_amt==4))

## [1] 78

mean(subset(df1$germinated,df1$Box=="Uncovered" & df1$water_amt==5))

## [1] 72.75

mean(subset(df1$germinated,df1$Box=="Uncovered" & df1$water_amt==6))

## [1] 0

Germination is increasing from water level 1-4 and decreases at water level 5 and it is 0 at
water level 6
b)Association of number of germinating seeds with the fact that the boxes were covered or
uncovered.
mean(subset(df1$germinated,df1$Box=="Covered"))

## [1] 47.29167

mean(subset(df1$germinated,df1$Box=="Uncovered"))

## [1] 47.95833

Germination is nearly equal in both the cases.

You might also like