Skip to content

Commit ef0c225

Browse files
committed
initial commit
0 parents  commit ef0c225

15 files changed

+696
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

Cars.csv

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"Name","Transmission","Cylinders","Fuel.Economy"
2+
"Mazda RX4","Manual",6,21
3+
"Mazda RX4 Wag","Manual",6,21
4+
"Datsun 710","Manual",4,22.8
5+
"Hornet 4 Drive","Automatic",6,21.4
6+
"Hornet Sport","Automatic",8,18.7
7+
"Valiant","Automatic",6,18.1
8+
"Duster 360","Automatic",8,14.3
9+
"Merc 240D","Automatic",4,24.4
10+
"Merc 230","Automatic",4,22.8
11+
"Merc 280","Automatic",6,19.2
12+
"Merc 280C","Automatic",6,17.8
13+
"Merc 450SE","Automatic",8,16.4
14+
"Merc 450SL","Automatic",8,17.3
15+
"Merc 450SLC","Automatic",8,15.2
16+
"Cadillac Fleetwood","Automatic",8,10.4
17+
"Lincoln Continental","Automatic",8,10.4
18+
"Chrysler Imperial","Automatic",8,14.7
19+
"Fiat 128","Manual",4,32.4
20+
"Honda Civic","Manual",4,30.4
21+
"Toyota Corolla","Manual",4,33.9
22+
"Toyota Corona","Automatic",4,21.5
23+
"Dodge Challenger","Automatic",8,15.5
24+
"AMC Javelin","Automatic",8,15.2
25+
"Camaro Z28","Automatic",8,13.3
26+
"Pontiac Firebird","Automatic",8,19.2
27+
"Fiat X1-9","Manual",4,27.3
28+
"Porsche 914-2","Manual",4,26
29+
"Lotus Europa","Manual",4,30.4
30+
"Ford Pantera L","Manual",8,15.8
31+
"Ferrari Dino","Manual",6,19.7
32+
"Maserati Bora","Manual",8,15
33+
"Volvo 142E","Manual",4,21.4

CreateStatisticalModels.R

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Creating Statistical Model
2+
3+
# Set working directory
4+
setwd("/Users/daviddryburgh/Documents/R_Programming")
5+
6+
# Load CSV file
7+
iris <- read.csv("Iris.csv")
8+
9+
# Peak at data
10+
head(iris)
11+
12+
# Create a scatterplot
13+
plot(
14+
x = iris$Petal.Length,
15+
y = iris$Petal.Width,
16+
main = "Iris Petal Length vs. Width",
17+
xlab = "Petal Length (cm)",
18+
ylab = "Petal width (cm)"
19+
)
20+
21+
# Create a linear regression model
22+
model <- lm(
23+
formula = Petal.Width ~ Petal.Length,
24+
data = iris
25+
)
26+
27+
# Summarize the model
28+
summary(model)
29+
30+
# Draw a regression line on plot
31+
lines(
32+
x = iris$Petal.Length,
33+
y = model$fitted,
34+
col = "red",
35+
lwd = 3
36+
)
37+
38+
# Get correlation coefficient
39+
cor(
40+
x = iris$Petal.Length,
41+
y = iris$Petal.Width
42+
)
43+
44+
# Predict new values from the model
45+
predict(
46+
object = model,
47+
newdata = data.frame(
48+
Petal.Length = c(2, 5, 7)
49+
)
50+
)

CreatingDataVisualisations.R

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#Creating Data Visualisation
2+
3+
# Set the working directory
4+
setwd("/Users/daviddryburgh/Documents/R_Programming")
5+
6+
# Read the CSV file
7+
cars <- read.csv("Cars.csv")
8+
9+
# Load the ggplot2 library
10+
library(ggplot2)
11+
12+
# Create a frequency bar chart
13+
ggplot(
14+
data = cars,
15+
aes(x = Transmission)) +
16+
geom_bar() +
17+
ggtitle("Count of Cars by Transmission Type") +
18+
xlab("Transmission Type") +
19+
ylab("Count of Cars")
20+
21+
# Create a histogram
22+
ggplot(
23+
data = cars,
24+
aes(x = Fuel.Economy)) +
25+
geom_histogram(
26+
bins = 10
27+
) +
28+
ggtitle("Distribution of Fuel Economy") +
29+
xlab("Fuel Economy") +
30+
ylab("Count of Cars")
31+
32+
# Create a density plot
33+
ggplot(
34+
data = cars,
35+
aes(x = Fuel.Economy)) +
36+
geom_density() +
37+
ggtitle("Distribution of Fuel Economy") +
38+
xlab("Fuel Economy (mpg)") +
39+
ylab("Density")
40+
41+
# Create a scatterplot
42+
ggplot(
43+
data = cars,
44+
aes(
45+
x = Cylinders,
46+
y = Fuel.Economy)) +
47+
geom_point() +
48+
ggtitle("Fuel Economy by Cylinders") +
49+
xlab("Number of Cylinders") +
50+
ylab("Fuel Economy (mpg)")
51+
52+

CreatingDescriptiveStatistics.R

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Creating Data Visualization
2+
3+
# Set the working directory
4+
setwd("/Users/daviddryburgh/Documents/R_Programming")
5+
6+
# Read the CSV file
7+
cars <- read.csv("Cars.csv")
8+
9+
# Peek at the data
10+
head(cars)
11+
12+
# Create a frequency table
13+
table(cars$Transmission)
14+
15+
# Get the minimum value
16+
min(cars$Fuel.Economy)
17+
18+
# Get the maximum value
19+
max(cars$Fuel.Economy)
20+
# Get the average vale
21+
mean(cars$Fuel.Economy)
22+
23+
# Get the median value
24+
median(cars$Fuel.Economy)
25+
26+
# Get the quartiles
27+
quantile(cars$Fuel.Economy)
28+
29+
# Get the standard deviation
30+
sd(cars$Fuel.Economy)
31+
32+
# Get the total value
33+
sum(cars$Fuel.Economy)
34+
35+
# Get the correlation coefficient
36+
cor(
37+
x = cars$Cylinders,
38+
y = cars$Fuel.Economy
39+
)
40+
41+
# Summarize and entire table
42+
summary(cars)

Fuel Efficiency.csv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"Cylinders","Avg.Consumption"
2+
4,9.7325
3+
6,8.128125
4+
8,6.39625

HandlingBigData.R

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Handling Big Data
2+
3+
# set working directory
4+
setwd("/Users/daviddryburgh/Documents/R_Programming")
5+
6+
# Load the ff package
7+
library(ff)
8+
9+
# Read a CSV file as ff data frame
10+
irisff <- read.table.ffdf(
11+
file = "Iris.csv",
12+
FUN = "read.csv"
13+
)
14+
15+
# Inspect the class
16+
class(irisff)
17+
18+
# Inspect the column names
19+
names(irisff)
20+
21+
# Inspect the first few rows
22+
irisff[1:5,]
23+
24+
# Load the biglm package
25+
library(biglm)
26+
27+
model <- biglm(
28+
formula = Petal.Width ~ Petal.Length,
29+
data = irisff
30+
)
31+
32+
# Summarize the model
33+
summary(model)
34+
35+
# Create a scatterplot
36+
plot(
37+
x = irisff$Petal.Length[],
38+
y = irisff$Petal.Width[],
39+
main = "Iris Petal Length vs. Width",
40+
xlab = "Petal Length(cm)",
41+
ylab = "Petal Width (cm)"
42+
)
43+
44+
# Get y-intercept from model
45+
b <- summary(model)$mat[1,1]
46+
47+
# Get slope from model
48+
m <- summary(model)$mat[2,1]
49+
50+
# Draw a regression line on plot
51+
lines(
52+
x = irisff$Petal.Length[],
53+
y = m * irisff$Petal.Length[] + b,
54+
col = "red",
55+
lwd = 3
56+
)
57+
58+
# Predict new values with the model
59+
predict(
60+
object = model,
61+
newdata = data.frame(
62+
Petal.Length = c(2, 5, 7),
63+
Petal.Width = c(0, 0, 0)
64+
)
65+
)

HelloWorld.R

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Assign a character string to a variable
2+
x <- "Hello World!"
3+
4+
#Print the variable
5+
prit(x)

0 commit comments

Comments
 (0)