-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipe1.R
More file actions
31 lines (25 loc) · 995 Bytes
/
Recipe1.R
File metadata and controls
31 lines (25 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## ------------------------------------------------------------------------
# Let's load some pre-defined R data
data(mtcars)
help (mtcars)
# Let's peek into the data
head(mtcars)
# Let's see its structure
str(mtcars)
## ------------------------------------------------------------------------
# Let's calculate the average MPG consumption
mean(mtcars$mpg)
# Let's calculate the standard deviation
sd(mtcars$mpg)
# Shortcut, calculate summary statistics
summary(mtcars$mpg)
# let's generate an histogram of the mpg variable with 10 bars
hist(mtcars$mpg,breaks=10,main="Histogram of MPG", xlab="Miles per Gallon (MPG)")
# Let's draw a vertical line at the mean
abline(v=mean(mtcars$mpg),col="red",lty=2)
# Calculate some bi-variate stats
#let's plot MPG vs weight
plot(mtcars$wt,mtcars$mpg, main="Automobile MPG vs Weight", ylab="Miles per Gallon (MPG)",xlab="Weight (lb/1000) ")
#There is a clear (inverse) relationship between both
#Let's calculate correlation
cor(mtcars$mpg,mtcars$wt)