Script Syntax
Script Syntax
#install packages
install.packages("readr")
install.packages("pander")
#load packages
library(readr)
library(pander)
#Example 1: Beverages
purchase<-read.csv("purchase.csv")
purchase
View(purchase)
#Frequency Table
purchase.freq <-table(purchase)
purchase.freq
freq.dist<-cbind(purchase.freq)
freq.dist
#label the column "Frequency"
colnames(freq.dist)<-c("Frequency")
freq.dist
pander(freq.dist)
#Example 2: Cars
Cars <-c(1, 2, 1, 0, 3, 4, 0, 1, 1, 2, 2, 3, 2, 1, 4, 0, 0)
Cars
car.freq <-table(Cars)
car.freq
car.relfreq<-(car.freq/sum(car.freq))
car.relfreq
car.percent
car.fredist
#Label the columns
car.fredist
#Output
pander(car.fredist)
#Import files
Rent <-read.csv("Rent.csv")
Rent
View (Rent)
#Create the Grouped Frequency Distribution Table. (Adjust to get an equal width)
breaks
classint
freq <-table(classint)
freq
freq.dist
#Label Columns
colnames(freq.dist)<-c("Frequency")
freq.dist
#Output
pander(freq.dist)
#Bar Graph
#Install packages
install.packages("tidyverse")
install.packages("forcats")
install.packages("readr")
#Load packages
library(readr)
library(tidyverse)
library(forcats)
purchase<-read.csv("purchase.csv")
purchase
bar1
bar2<- ggplot(mutate(purchase,Purchase=fct_infreq(Purchase)))+geom_bar(aes(x=Purchase))
bar2
#Pie Chart
library(readr)
purchase <-read.csv("purchase.csv")
purchase
data.freq <-table(purchase)
data.freq
freq
#Label
label
percent
label
label
#Dot Plot
install.packages("ggplot2")
library(readr)
library(ggplot2)
cars<-c(1, 2, 1, 0, 3, 4, 0, 1, 1, 1, 2, 2, 3, 2, 3, 1, 4, 0, 0)
cars
cars<-read.csv("Cars.csv")
cars
#Use this syntax to generate the dot plot when the file is imported
dplot
data
stem(data)
library(readr)
#Import the file and save to the object named data
data <-read.csv("inflation.csv")
data
head(data)
#Select only the variable "Inflation" and store in the object named inf
inf <-data$Inflation
inf
output<-stem(inf,scale=2)
#Histogram
library(readr)
#Import file
data <-read.csv("Rent.csv")
data
#Generate the Histogram
#Crosstabulation
install.packages("summarytools")
library(readr)
library(summarytools)
library(pander)
salary<-read.csv("salaries.csv")
salary
head(salary)
crosstab
#Generate the cross-tabulation table
pander(crosstab)
#Scatter Diagram/Plot
library(readr)
data<-read.csv("Advertising.csv")
data
head(data)
plot(x=data$Number.of.Commercials, y=data$Sale,
abline(lm(data$Sales~data$Number.of.Commercials))