//Sample Solution
const gameState = {}
function preload() {
this.load.image('codey', 'https://s3.amazonaws.com/codecademy-content/courses/learn-phaser/codey.png');
}
function create() {
gameState.codey = this.add.sprite(150, 200, 'codey')
// Set cursor keys here!
gameState.cursors = this.input.keyboard.createCursorKeys();
}
function update() {
// Update based on keypress here!
if(gameState.cursors.right.isDown){
gameState.codey.x += 5
}
if(gameState.cursors.left.isDown){
gameState.codey.x -= 5
}
if(gameState.cursors.up.isDown){
gameState.codey.y -= 5
}
if(gameState.cursors.down.isDown){
gameState.codey.y += 5
}
}
const config = {
type: Phaser.AUTO,
width: 400,
height: 500,
backgroundColor: "#5f2a55",
scene: {
preload,
create,
update
}
}
const game = new Phaser.Game(config)
Quotes help make search much faster. Example: "Practice Makes Perfect"
Monday, September 9, 2019
Codecademy Learn Phaser: Basics Storing State 8/12
//Sample Solution
const gameState = {};
function create() {
gameState.circle = this.add.circle(40, 100, 20, 0xff9999)
}
function update() {
gameState.circle.y += 1
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
backgroundColor: "#99ff99",
scene: {
create,
update
}
}
const game = new Phaser.Game(config)
const gameState = {};
function create() {
gameState.circle = this.add.circle(40, 100, 20, 0xff9999)
}
function update() {
gameState.circle.y += 1
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
backgroundColor: "#99ff99",
scene: {
create,
update
}
}
const game = new Phaser.Game(config)
Codecademy Learn Phaser: Basics Move Your Bodies 7/12
//Sample Solution
let codey;
function preload() {
this.load.image('codey', 'https://s3.amazonaws.com/codecademy-content/courses/learn-phaser/codey.png');
}
function create() {
codey = this.add.sprite(30, 200, 'codey')
}
// Create your update() function here
function update() {
codey.x += 1;
}
const config = {
type: Phaser.AUTO,
width: 400,
height: 400,
backgroundColor: "#5f2a55",
scene: {
preload,
create,
// Include update here!
update
}
}
const game = new Phaser.Game(config)
let codey;
function preload() {
this.load.image('codey', 'https://s3.amazonaws.com/codecademy-content/courses/learn-phaser/codey.png');
}
function create() {
codey = this.add.sprite(30, 200, 'codey')
}
// Create your update() function here
function update() {
codey.x += 1;
}
const config = {
type: Phaser.AUTO,
width: 400,
height: 400,
backgroundColor: "#5f2a55",
scene: {
preload,
create,
// Include update here!
update
}
}
const game = new Phaser.Game(config)
Codecademy Learn Phaser: Basics Start Making A Scene 6/12
//Sample Solution
// Create a create() function here:
function create() {
this.add.text(100,170,"Spaze Invaydurs");
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
backgroundColor: "#a0a0dd",
// Add in the scene information in the config here:
scene: {
create
}
}
const game = new Phaser.Game(config)
// Create a create() function here:
function create() {
this.add.text(100,170,"Spaze Invaydurs");
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
backgroundColor: "#a0a0dd",
// Add in the scene information in the config here:
scene: {
create
}
}
const game = new Phaser.Game(config)
Codecademy Learn Phaser: Basics Create A Config 5/12
//Sample Solution
const config = {
width: 450,
height: 600,
backgroundColor: "#0000ff",
}
const game = new Phaser.Game(config)
const config = {
width: 450,
height: 600,
backgroundColor: "#0000ff",
}
const game = new Phaser.Game(config)
Codecademy Learn Phaser: Basics Draw A Background Image 4/12
//Sample Solution
function preload() {
// Load in the background image here!
this.load.image('sky','https://s3.amazonaws.com/codecademy-content/courses/learn-phaser/sky.jpg');
}
function create() {
// Put the background image in the scene here!
this.add.image(200,200,'sky');
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
backgroundColor: "#5f2a55",
scene: {
create,
preload
}
}
const game = new Phaser.Game(config)
function preload() {
// Load in the background image here!
this.load.image('sky','https://s3.amazonaws.com/codecademy-content/courses/learn-phaser/sky.jpg');
}
function create() {
// Put the background image in the scene here!
this.add.image(200,200,'sky');
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
backgroundColor: "#5f2a55",
scene: {
create,
preload
}
}
const game = new Phaser.Game(config)
Codecademy Learn Phaser: Basics Draw A Sprite 3/12
//Sample Solution
function preload() {
// Load in the sprite here!
this.load.image('codey','https://s3.amazonaws.com/codecademy-content/courses/learn-phaser/codey.png')
}
function create() {
// Create a sprite game object here!
this.add.sprite(40,50,'codey')
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
backgroundColor: "#5f2a55",
scene: {
create,
preload
}
}
const game = new Phaser.Game(config)
function preload() {
// Load in the sprite here!
this.load.image('codey','https://s3.amazonaws.com/codecademy-content/courses/learn-phaser/codey.png')
}
function create() {
// Create a sprite game object here!
this.add.sprite(40,50,'codey')
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
backgroundColor: "#5f2a55",
scene: {
create,
preload
}
}
const game = new Phaser.Game(config)
Codecademy Learn Phaser: Basics Draw A Circle 2/12
//Sample Solution
function create() {
let circle1 = this.add.circle(50, 100, 90, 0xFFF070);
let circle2 = this.add.circle(95, 300, 80, 0xFF0000);
let circle3 = this.add.circle(200, 200, 100, 0x9F00D0);
let circle4 = this.add.circle(300, 400, 10, 0x00E030);
// Add in a circle here!
let circle5 = this.add.circle(450, 600, 240, 0xFFFFFF);
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
scene: {
create
}
}
const game = new Phaser.Game(config)
function create() {
let circle1 = this.add.circle(50, 100, 90, 0xFFF070);
let circle2 = this.add.circle(95, 300, 80, 0xFF0000);
let circle3 = this.add.circle(200, 200, 100, 0x9F00D0);
let circle4 = this.add.circle(300, 400, 10, 0x00E030);
// Add in a circle here!
let circle5 = this.add.circle(450, 600, 240, 0xFFFFFF);
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
scene: {
create
}
}
const game = new Phaser.Game(config)
Codecademy Learn Phaser: Basics Hello World 1/12
//Sample Solution
function create() {
// Change "Codey's Adventures\n in Code World" to the name of your game
this.add.text(50, 100, "Nathan's Nation", { font: "40px Times New Roman", fill: "#ffa0d0"});
// Change "by Codecademy" to your name!
this.add.text(130, 300, "by nathan", { font: "20px Times New Roman", fill: "#ffa0d0"});
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
backgroundColor: "#5f2a55",
scene: {
create
}
};
const game = new Phaser.Game(config);
function create() {
// Change "Codey's Adventures\n in Code World" to the name of your game
this.add.text(50, 100, "Nathan's Nation", { font: "40px Times New Roman", fill: "#ffa0d0"});
// Change "by Codecademy" to your name!
this.add.text(130, 300, "by nathan", { font: "20px Times New Roman", fill: "#ffa0d0"});
}
const config = {
type: Phaser.AUTO,
width: 450,
height: 600,
backgroundColor: "#5f2a55",
scene: {
create
}
};
const game = new Phaser.Game(config);
Codecademy Hypothesis Testing With R ANOVA 13/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r message = FALSE}
# load data
load("dist_one.Rda")
load("dist_two.Rda")
load("dist_three.Rda")
load("dist_four.Rda")
```
```{r}
# plot histograms and define not_normal here:
hist(dist_one)
hist(dist_two)
hist(dist_three)
hist(dist_four)
not_normal <- 4
```
```{r}
# define ratio here:
ratio <- sd(dist_two)/sd(dist_three)
ratio
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r message = FALSE}
# load data
load("dist_one.Rda")
load("dist_two.Rda")
load("dist_three.Rda")
load("dist_four.Rda")
```
```{r}
# plot histograms and define not_normal here:
hist(dist_one)
hist(dist_two)
hist(dist_three)
hist(dist_four)
not_normal <- 4
```
```{r}
# define ratio here:
ratio <- sd(dist_two)/sd(dist_three)
ratio
```
Codecademy Hypothesis Testing With R ANOVA 12/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r message = FALSE}
# load libraries
library(tidyr)
```
```{r message = FALSE}
# load data
load("stores.Rda")
load("stores_new.Rda")
```
```{r}
# inspect stores here:
stores
```
```{r}
# perform anova on stores here:
results = aov(sales ~ store, data = stores)
summary(results)
```
```{r}
# perform anova on stores_new here:
results_new = aov(sales ~ store, data = stores_new)
summary(results_new)
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r message = FALSE}
# load libraries
library(tidyr)
```
```{r message = FALSE}
# load data
load("stores.Rda")
load("stores_new.Rda")
```
```{r}
# inspect stores here:
stores
```
```{r}
# perform anova on stores here:
results = aov(sales ~ store, data = stores)
summary(results)
```
```{r}
# perform anova on stores_new here:
results_new = aov(sales ~ store, data = stores_new)
summary(results_new)
```
Codecademy Hypothesis Testing With R Dangers of Multiple T-Tests 11/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r message = FALSE}
# load data
load("store_a.Rda")
load("store_b.Rda")
load("store_c.Rda")
```
```{r}
# calculate means here:
store_a_mean <- mean(store_a)
store_a_mean
store_b_mean <- mean(store_b)
store_b_mean
store_c_mean <- mean(store_c)
store_c_mean
```
```{r}
# calculate standard deviations here:
store_a_sd <- sd(store_a)
store_a_sd
store_b_sd <- sd(store_b)
store_b_sd
store_c_sd <- sd(store_c)
store_c_sd
```
```{r}
# perform two sample t-test here:
a_b_results <- t.test(store_a,store_b)
a_b_results
a_c_results <- t.test(store_a,store_c)
a_c_results
b_c_results <- t.test(store_b,store_c)
b_c_results
```
```{r}
# calculate error_prob here:
error_prob <- (1-(0.95**3))
error_prob
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r message = FALSE}
# load data
load("store_a.Rda")
load("store_b.Rda")
load("store_c.Rda")
```
```{r}
# calculate means here:
store_a_mean <- mean(store_a)
store_a_mean
store_b_mean <- mean(store_b)
store_b_mean
store_c_mean <- mean(store_c)
store_c_mean
```
```{r}
# calculate standard deviations here:
store_a_sd <- sd(store_a)
store_a_sd
store_b_sd <- sd(store_b)
store_b_sd
store_c_sd <- sd(store_c)
store_c_sd
```
```{r}
# perform two sample t-test here:
a_b_results <- t.test(store_a,store_b)
a_b_results
a_c_results <- t.test(store_a,store_c)
a_c_results
b_c_results <- t.test(store_b,store_c)
b_c_results
```
```{r}
# calculate error_prob here:
error_prob <- (1-(0.95**3))
error_prob
```
Codecademy Hypothesis Testing With R Two-Sample T-Test 10/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r message = FALSE}
# load data
load("week_1.Rda")
week_1
load("week_2.Rda")
week_2
```
```{r}
# calculate week_1_mean and week_2_mean here:
week_1_mean <- mean(week_1)
week_1_mean
week_2_mean <- mean(week_2)
week_2_mean
```
```{r}
# calculate week_1_sd and week_2_sd here:
week_1_sd <- sd(week_1)
week_1_sd
week_2_sd <- sd(week_2)
week_2_sd
```
```{r}
# run two sample t-test here:
results <- t.test(week_1,week_2)
results
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r message = FALSE}
# load data
load("week_1.Rda")
week_1
load("week_2.Rda")
week_2
```
```{r}
# calculate week_1_mean and week_2_mean here:
week_1_mean <- mean(week_1)
week_1_mean
week_2_mean <- mean(week_2)
week_2_mean
```
```{r}
# calculate week_1_sd and week_2_sd here:
week_1_sd <- sd(week_1)
week_1_sd
week_2_sd <- sd(week_2)
week_2_sd
```
```{r}
# run two sample t-test here:
results <- t.test(week_1,week_2)
results
```
Codecademy Hypothesis Testing With R One-Sample T-Test 9/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r message = FALSE}
# load and view data
load("ages.Rda")
ages
```
```{r}
# calculate ages_mean here:
ages_mean <- mean(ages)
ages_mean
```
```{r}
# perform t-test here:
results <- t.test(ages,mu=30)
results
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r message = FALSE}
# load and view data
load("ages.Rda")
ages
```
```{r}
# calculate ages_mean here:
ages_mean <- mean(ages)
ages_mean
```
```{r}
# perform t-test here:
results <- t.test(ages,mu=30)
results
```
Codecademy Hypothesis Testing With R Significance Level 8/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# update reject_hypothesis here:
# all p-values below the threshold will result in # # rejecting the null hypothesis
# p-value threshold industry = 0.05
# hypothesis test actual p-value = 0.1 > 0.05
# since p-value is larger than the threshold, we # accept the null hypothesis
reject_hypothesis <- FALSE
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# update reject_hypothesis here:
# all p-values below the threshold will result in # # rejecting the null hypothesis
# p-value threshold industry = 0.05
# hypothesis test actual p-value = 0.1 > 0.05
# since p-value is larger than the threshold, we # accept the null hypothesis
reject_hypothesis <- FALSE
```
Codecademy Hypothesis Testing With R P-Values 7/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# possible interpretations
st_1 <- "There is a 20% chance that the difference in average weight of green and red apples is due to random sampling."
st_2 <- "There is a 20% chance that green and red apples have the same average weight."
st_3 <- "There is a 20% chance red apples weigh more than green apples."
st_4 <- "There is a 20% chance green apples weigh more than green apples."
# update the value of interpretation here:
interpretation <- "st_1"
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# possible interpretations
st_1 <- "There is a 20% chance that the difference in average weight of green and red apples is due to random sampling."
st_2 <- "There is a 20% chance that green and red apples have the same average weight."
st_3 <- "There is a 20% chance red apples weigh more than green apples."
st_4 <- "There is a 20% chance green apples weigh more than green apples."
# update the value of interpretation here:
interpretation <- "st_1"
```
Codecademy Hypothesis Testing With R Type I and Type II Errors 6/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# the true positives and negatives:
actual_positive <- c(2, 5, 6, 7, 8, 10, 18, 21, 24, 25, 29, 30, 32, 33, 38, 39, 42, 44, 45, 47)
actual_negative <- c(1, 3, 4, 9, 11, 12, 13, 14, 15, 16, 17, 19, 20, 22, 23, 26, 27, 28, 31, 34, 35, 36, 37, 40, 41, 43, 46, 48, 49)
# the positives and negatives we determine by running the experiment:
experimental_positive <- c(2, 4, 5, 7, 8, 9, 10, 11, 13, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 27, 28, 32, 35, 36, 38, 39, 40, 45, 46, 49)
experimental_negative <- c(1, 3, 6, 12, 14, 23, 25, 29, 30, 31, 33, 34, 37, 41, 42, 43, 44, 47, 48)
```
```{r}
# define type_i_errors and type_ii_errors here:
type_i_errors = intersect(experimental_positive,actual_negative)
type_i_errors
type_ii_errors =
intersect(experimental_negative,actual_positive)
type_ii_errors
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# the true positives and negatives:
actual_positive <- c(2, 5, 6, 7, 8, 10, 18, 21, 24, 25, 29, 30, 32, 33, 38, 39, 42, 44, 45, 47)
actual_negative <- c(1, 3, 4, 9, 11, 12, 13, 14, 15, 16, 17, 19, 20, 22, 23, 26, 27, 28, 31, 34, 35, 36, 37, 40, 41, 43, 46, 48, 49)
# the positives and negatives we determine by running the experiment:
experimental_positive <- c(2, 4, 5, 7, 8, 9, 10, 11, 13, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 27, 28, 32, 35, 36, 38, 39, 40, 45, 46, 49)
experimental_negative <- c(1, 3, 6, 12, 14, 23, 25, 29, 30, 31, 33, 34, 37, 41, 42, 43, 44, 47, 48)
```
```{r}
# define type_i_errors and type_ii_errors here:
type_i_errors = intersect(experimental_positive,actual_negative)
type_i_errors
type_ii_errors =
intersect(experimental_negative,actual_positive)
type_ii_errors
```
Codecademy Hypothesis Testing With R Designing an Experiment 5/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# load data
load("retriever_lengths.Rda")
load("doodle_lengths.Rda")
```
```{r}
# calculate mean_retriever_l and mean_doodle_l here:
mean_retriever_l = mean(retriever_lengths)
mean_doodle_l = mean(doodle_lengths)
mean_retriever_l
mean_doodle_l
```
```{r}
# calculate mean_difference here:
mean_difference = mean_retriever_l - mean_doodle_l
mean_difference
```
```{r}
# statements:
st_1 <- "The average length of Golden Retrievers is 2.5 inches longer than the average length of Goldendoodles."
st_2 <- "The average length of Golden Retrievers is the same as the average length of Goldendoodles."
# update null_hypo here:
null_hypo <- "st_2"
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# load data
load("retriever_lengths.Rda")
load("doodle_lengths.Rda")
```
```{r}
# calculate mean_retriever_l and mean_doodle_l here:
mean_retriever_l = mean(retriever_lengths)
mean_doodle_l = mean(doodle_lengths)
mean_retriever_l
mean_doodle_l
```
```{r}
# calculate mean_difference here:
mean_difference = mean_retriever_l - mean_doodle_l
mean_difference
```
```{r}
# statements:
st_1 <- "The average length of Golden Retrievers is 2.5 inches longer than the average length of Goldendoodles."
st_2 <- "The average length of Golden Retrievers is the same as the average length of Goldendoodles."
# update null_hypo here:
null_hypo <- "st_2"
```
Saturday, September 7, 2019
Codecademy Hypothesis Testing With R Hypothesis Formulation 4/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# experiment 1
hypo_a <- "DeePressurize lowers blood pressure in patients."
hypo_b <- "DeePressurize has no effect on blood pressure in patients."
null_hypo_1 <- "hypo_b"
```
```{r}
# experiment 2
hypo_c <- "The new profile layout has no effect on number of matches with other users."
hypo_d <- "The new profile layout results in more matches with other users than the original layout."
null_hypo_2 <- "hypo_c"
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# experiment 1
hypo_a <- "DeePressurize lowers blood pressure in patients."
hypo_b <- "DeePressurize has no effect on blood pressure in patients."
null_hypo_1 <- "hypo_b"
```
```{r}
# experiment 2
hypo_c <- "The new profile layout has no effect on number of matches with other users."
hypo_d <- "The new profile layout results in more matches with other users than the original layout."
null_hypo_2 <- "hypo_c"
```
Codecademy Hypothesis Testing With R Sample Mean and Population Mean - I 2/14
#Sample Solution
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# generate random population
population <- rnorm(300, mean=65, sd=3.5)
# calculate population mean here:
population_mean <- mean(population)
population_mean
```
```{r}
# generate sample 1
sample_1 <- sample(population, size=30)
sample_1
# calculate sample 1 mean
sample_1_mean <- mean(sample_1)
sample_1_mean
```
```{r}
# generate samples 2,3,4 and 5
sample_2 <- sample(population, size=30)
sample_3 <- sample(population, size=30)
sample_4 <- sample(population, size=30)
sample_5 <- sample(population, size=30)
```
```{r}
# calculate sample means here:
sample_2_mean <- mean(sample_2)
sample_2_mean
sample_3_mean <- mean(sample_3)
sample_3_mean
sample_4_mean <- mean(sample_4)
sample_4_mean
sample_5_mean <- mean(sample_5)
sample_5_mean
```
---
title: "Hypothesis Testing in R"
output: html_notebook
---
```{r}
# generate random population
population <- rnorm(300, mean=65, sd=3.5)
# calculate population mean here:
population_mean <- mean(population)
population_mean
```
```{r}
# generate sample 1
sample_1 <- sample(population, size=30)
sample_1
# calculate sample 1 mean
sample_1_mean <- mean(sample_1)
sample_1_mean
```
```{r}
# generate samples 2,3,4 and 5
sample_2 <- sample(population, size=30)
sample_3 <- sample(population, size=30)
sample_4 <- sample(population, size=30)
sample_5 <- sample(population, size=30)
```
```{r}
# calculate sample means here:
sample_2_mean <- mean(sample_2)
sample_2_mean
sample_3_mean <- mean(sample_3)
sample_3_mean
sample_4_mean <- mean(sample_4)
sample_4_mean
sample_5_mean <- mean(sample_5)
sample_5_mean
```
Codecademy Interquartile Range IQR in R 3/4
Codecademy Interquartile Range IQR in R 3/4
#Sample Solution
---
title: "Interquartile Range"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
```
```{r}
# create the variable interquartile_range here
interquartile_range = IQR(songs)
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The IQR of the dataset is",interquartile_range)), error=function(e) {print("You haven't defined interquartile_range yet")})
```
#Sample Solution
---
title: "Interquartile Range"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
```
```{r}
# create the variable interquartile_range here
interquartile_range = IQR(songs)
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The IQR of the dataset is",interquartile_range)), error=function(e) {print("You haven't defined interquartile_range yet")})
```
Codecademy Interquartile Range Quartiles 2/4
#Sample Solution
---
title: "Interquartile Range"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
```
```{r}
# find the first quartile
q1 <- quantile(songs,0.25)
```
```{r}
# calculate the third quartile here:
q3 <- quantile(songs,0.75)
```
```{r}
# calculate the interquartile range here:
interquartile_range <- q3 - q1
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The first quartile of the dataset is",q1)), error=function(e) {print("You haven't defined q1 yet")})
tryCatch(print(paste("The third quartile of the dataset is",q3)), error=function(e) {print("You haven't defined q3 yet")})
tryCatch(print(paste("The IQR of the dataset is",interquartile_range)), error=function(e) {print("You haven't defined interquartile_range yet")})
```
---
title: "Interquartile Range"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
```
```{r}
# find the first quartile
q1 <- quantile(songs,0.25)
```
```{r}
# calculate the third quartile here:
q3 <- quantile(songs,0.75)
```
```{r}
# calculate the interquartile range here:
interquartile_range <- q3 - q1
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The first quartile of the dataset is",q1)), error=function(e) {print("You haven't defined q1 yet")})
tryCatch(print(paste("The third quartile of the dataset is",q3)), error=function(e) {print("You haven't defined q3 yet")})
tryCatch(print(paste("The IQR of the dataset is",interquartile_range)), error=function(e) {print("You haven't defined interquartile_range yet")})
```
Codecademy Interquartile Range Range Review 1/4
#Sample Solution
---
title: "Interquartile Range"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(ggplot2)
```
```{r}
# load song data
load("songs.Rda")
```
```{r}
# find maximum and minimum song lengths
maximum <- max(songs)
minimum <- min(songs)
```
```{r}
# create variable song_range here:
song_range <- maximum - minimum
```
```{r message=FALSE, echo=FALSE}
# plot histogram
hist <- qplot(songs,
geom="histogram",
main = 'Histogram of Song Lengths',
xlab = 'Song Length (Seconds)',
ylab = 'Count',
fill=I("blue"),
col=I("red"),
alpha=I(.2))
hist
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The range of the dataset is",song_range)), error=function(e) {print("You haven't defined the variable song_range yet")})
```
---
title: "Interquartile Range"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(ggplot2)
```
```{r}
# load song data
load("songs.Rda")
```
```{r}
# find maximum and minimum song lengths
maximum <- max(songs)
minimum <- min(songs)
```
```{r}
# create variable song_range here:
song_range <- maximum - minimum
```
```{r message=FALSE, echo=FALSE}
# plot histogram
hist <- qplot(songs,
geom="histogram",
main = 'Histogram of Song Lengths',
xlab = 'Song Length (Seconds)',
ylab = 'Count',
fill=I("blue"),
col=I("red"),
alpha=I(.2))
hist
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The range of the dataset is",song_range)), error=function(e) {print("You haven't defined the variable song_range yet")})
```
Friday, September 6, 2019
Codecademy Quantiles Common Quantiles 4/5
#Sample Solution
---
title: "Quantiles"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
```
```{r}
# define percentile and answer here:
percentile <- quantile(songs,0.32)
answer <- "below"
```
```{r}
# ignore the code below here:
tryCatch(print(paste("Your percentile is",percentile)), error=function(e) {print("You haven't defined percentile")})
```
---
title: "Quantiles"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
```
```{r}
# define percentile and answer here:
percentile <- quantile(songs,0.32)
answer <- "below"
```
```{r}
# ignore the code below here:
tryCatch(print(paste("Your percentile is",percentile)), error=function(e) {print("You haven't defined percentile")})
```
Codecademy Quantiles Many Quantiles 3/5
#Sample Solution
---
title: "Quantiles"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
```
```{r}
# define quartiles and deciles here:
quartiles <- quantile(songs, c(0.25, 0.5, 0.75))
decile_array <- c()
for(k in 1:9){
decile_array[k]<-k/10
}
decile_array
deciles <- quantile(songs, decile_array)
deciles
```
```{r}
# define tenth here:
tenth <- 3
```
```{r}
# ignore the code below here:
tryCatch(print(paste(c("The quartiles are",quartiles,collapse=" "))), error=function(e) {print("You haven't defined quartiles.")})
tryCatch(print(paste(c("The deciles are",deciles,collapse=" "))), error=function(e) {print("You haven't defined deciles.")})
```
---
title: "Quantiles"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
```
```{r}
# define quartiles and deciles here:
quartiles <- quantile(songs, c(0.25, 0.5, 0.75))
decile_array <- c()
for(k in 1:9){
decile_array[k]<-k/10
}
decile_array
deciles <- quantile(songs, decile_array)
deciles
```
```{r}
# define tenth here:
tenth <- 3
```
```{r}
# ignore the code below here:
tryCatch(print(paste(c("The quartiles are",quartiles,collapse=" "))), error=function(e) {print("You haven't defined quartiles.")})
tryCatch(print(paste(c("The deciles are",deciles,collapse=" "))), error=function(e) {print("You haven't defined deciles.")})
```
Codecademy Quantiles in R 2/5
#Sample Solution
---
title: "Quantiles"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
```
```{r}
# define twenty_third_percentile here:
twenty_third_percentile <- quantile(songs,0.23)
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The value that splits 23% of the data is",twenty_third_percentile)), error=function(e) {print("You haven't defined twenty_third_percentile.")})
```
---
title: "Quantiles"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
```
```{r}
# define twenty_third_percentile here:
twenty_third_percentile <- quantile(songs,0.23)
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The value that splits 23% of the data is",twenty_third_percentile)), error=function(e) {print("You haven't defined twenty_third_percentile.")})
```
Thursday, September 5, 2019
Codecademy Quartiles Quartiles in R 5/6
#Sample Solution
---
title: "Quartiles"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
songs
```
```{r}
# create the variables songs_q1, songs_q2, and songs_q3 here:
songs_q1 <- quantile(songs, 0.25)
songs_q2 <- quantile(songs, 0.50)
songs_q3 <- quantile(songs, 0.75)
```
```{r}
# create the variables favorite_song and quarter here:
favorite_song <- 209.13587
quarter <- 2
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The first quartile of dataset one is",songs_q1)), error=function(e) {print("You haven't defined songs_q1")})
tryCatch(print(paste("The second quartile of dataset two is",songs_q2)), error=function(e) {print("You haven't defined songs_q2")})
tryCatch(print(paste("The third quartile of dataset one is",songs_q3)), error=function(e) {print("You haven't defined songs_q3")})
```
---
title: "Quartiles"
output: html_notebook
---
```{r}
# load song data
load("songs.Rda")
songs
```
```{r}
# create the variables songs_q1, songs_q2, and songs_q3 here:
songs_q1 <- quantile(songs, 0.25)
songs_q2 <- quantile(songs, 0.50)
songs_q3 <- quantile(songs, 0.75)
```
```{r}
# create the variables favorite_song and quarter here:
favorite_song <- 209.13587
quarter <- 2
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The first quartile of dataset one is",songs_q1)), error=function(e) {print("You haven't defined songs_q1")})
tryCatch(print(paste("The second quartile of dataset two is",songs_q2)), error=function(e) {print("You haven't defined songs_q2")})
tryCatch(print(paste("The third quartile of dataset one is",songs_q3)), error=function(e) {print("You haven't defined songs_q3")})
```
Codecademy Quartiles Method Two: Including Q2 4/6
#Sample Solution
---
title: "Quartiles"
output: html_notebook
---
```{r}
dataset_one <- c(50, 10, 4, -3, 4, -20, 2)
# sorted dataset_one: [-20, -3, 2, 4, 4, 10, 50]
dataset_two <- c(24, 20, 1, 45, -15, 40)
# sorted dataset_two: c(-15, 1, 20, 24, 40, 45)
dataset_one_q2 <- 4
dataset_two_q2 <- 22
# define the first and third quartile of both datasets here:
dataset_one_q1 <- -0.5
dataset_one_q3 <- 7
dataset_two_q1 <- 1
dataset_two_q3 <- 40
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The first quartile of dataset one is",dataset_one_q1)), error=function(e) {print("You haven't defined dataset_one_q1")})
tryCatch(print(paste("The third quartile of dataset one is",dataset_one_q3)), error=function(e) {print("You haven't defined dataset_one_q3")})
tryCatch(print(paste("The first quartile of dataset two is",dataset_two_q1)), error=function(e) {print("You haven't defined dataset_two_q1")})
tryCatch(print(paste("The third quartile of dataset two is",dataset_two_q3)), error=function(e) {print("You haven't defined dataset_two_q3")})
```
---
title: "Quartiles"
output: html_notebook
---
```{r}
dataset_one <- c(50, 10, 4, -3, 4, -20, 2)
# sorted dataset_one: [-20, -3, 2, 4, 4, 10, 50]
dataset_two <- c(24, 20, 1, 45, -15, 40)
# sorted dataset_two: c(-15, 1, 20, 24, 40, 45)
dataset_one_q2 <- 4
dataset_two_q2 <- 22
# define the first and third quartile of both datasets here:
dataset_one_q1 <- -0.5
dataset_one_q3 <- 7
dataset_two_q1 <- 1
dataset_two_q3 <- 40
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The first quartile of dataset one is",dataset_one_q1)), error=function(e) {print("You haven't defined dataset_one_q1")})
tryCatch(print(paste("The third quartile of dataset one is",dataset_one_q3)), error=function(e) {print("You haven't defined dataset_one_q3")})
tryCatch(print(paste("The first quartile of dataset two is",dataset_two_q1)), error=function(e) {print("You haven't defined dataset_two_q1")})
tryCatch(print(paste("The third quartile of dataset two is",dataset_two_q3)), error=function(e) {print("You haven't defined dataset_two_q3")})
```
Codecademy Quartiles Q1 and Q3 3/6
#Sample Solution
---
title: "Quartiles"
output: html_notebook
---
```{r}
dataset_one <- c(50, 10, 4, -3, 4, -20, 2)
# sorted dataset_one: [-20, -3, 2, 4, 4, 10, 50]
dataset_two <- c(24, 20, 1, 45, -15, 40)
# sorted dataset_two: c(-15, 1, 20, 24, 40, 45)
dataset_one_q2 <- 4
dataset_two_q2 <- 22
# define the first and third quartile of both datasets here:
dataset_one_q1 <- -3
dataset_one_q3 <- 10
dataset_two_q1 <- 1
dataset_two_q3 <- 40
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The first quartile of dataset one is",dataset_one_q1)), error=function(e) {print("You haven't defined dataset_one_q1")})
tryCatch(print(paste("The third quartile of dataset one is",dataset_one_q3)), error=function(e) {print("You haven't defined dataset_one_q3")})
tryCatch(print(paste("The first quartile of dataset two is",dataset_two_q1)), error=function(e) {print("You haven't defined dataset_two_q1")})
tryCatch(print(paste("The third quartile of dataset two is",dataset_two_q3)), error=function(e) {print("You haven't defined dataset_two_q3")})
```
---
title: "Quartiles"
output: html_notebook
---
```{r}
dataset_one <- c(50, 10, 4, -3, 4, -20, 2)
# sorted dataset_one: [-20, -3, 2, 4, 4, 10, 50]
dataset_two <- c(24, 20, 1, 45, -15, 40)
# sorted dataset_two: c(-15, 1, 20, 24, 40, 45)
dataset_one_q2 <- 4
dataset_two_q2 <- 22
# define the first and third quartile of both datasets here:
dataset_one_q1 <- -3
dataset_one_q3 <- 10
dataset_two_q1 <- 1
dataset_two_q3 <- 40
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The first quartile of dataset one is",dataset_one_q1)), error=function(e) {print("You haven't defined dataset_one_q1")})
tryCatch(print(paste("The third quartile of dataset one is",dataset_one_q3)), error=function(e) {print("You haven't defined dataset_one_q3")})
tryCatch(print(paste("The first quartile of dataset two is",dataset_two_q1)), error=function(e) {print("You haven't defined dataset_two_q1")})
tryCatch(print(paste("The third quartile of dataset two is",dataset_two_q3)), error=function(e) {print("You haven't defined dataset_two_q3")})
```
Codecademy Quartiles The Second Quartile 2/6
#Sample Solution
---
title: "Quartiles"
output: html_notebook
---
```{r}
dataset_one <- c(50, 10, 4, -3, 4, -20, 2)
# sorted dataset_one: c(-20, -3, 2, 4, 4, 10, 50)
dataset_two <- c(24, 20, 1, 45, -15, 40)
# sorted dataset_two: c(-15, 1, 20, 24, 40, 45)
# define the second quartile of both datasets here:
dataset_one_q2 <- 4
dataset_two_q2 <- 22
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The second quartile of dataset one is",dataset_one_q2)), error=function(e) {print("You haven't defined dataset_one_q2")})
tryCatch(print(paste("The second quartile of dataset two is",dataset_two_q2)), error=function(e) {print("You haven't defined dataset_two_q2")})
```
---
title: "Quartiles"
output: html_notebook
---
```{r}
dataset_one <- c(50, 10, 4, -3, 4, -20, 2)
# sorted dataset_one: c(-20, -3, 2, 4, 4, 10, 50)
dataset_two <- c(24, 20, 1, 45, -15, 40)
# sorted dataset_two: c(-15, 1, 20, 24, 40, 45)
# define the second quartile of both datasets here:
dataset_one_q2 <- 4
dataset_two_q2 <- 22
```
```{r}
# ignore the code below here:
tryCatch(print(paste("The second quartile of dataset one is",dataset_one_q2)), error=function(e) {print("You haven't defined dataset_one_q2")})
tryCatch(print(paste("The second quartile of dataset two is",dataset_two_q2)), error=function(e) {print("You haven't defined dataset_two_q2")})
```
Codecademy Standard Deviation in R 3/5
#Sample Solution
---
title: "Standard Deviation"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(tidyr)
```
```{r}
# Import data
load("lesson_data.Rda")
```
```{r}
# Change these variables to be the standard deviation of each dataset.
nba_standard_deviation <- sd(nba_data)
okcupid_standard_deviation <- sd(okcupid_data)
#IGNORE CODE BELOW HERE
print(paste("The standard deviation of the NBA dataset is ",nba_standard_deviation))
print(paste("The standard deviation of the OkCupid dataset is ", okcupid_standard_deviation))
```
---
title: "Standard Deviation"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(tidyr)
```
```{r}
# Import data
load("lesson_data.Rda")
```
```{r}
# Change these variables to be the standard deviation of each dataset.
nba_standard_deviation <- sd(nba_data)
okcupid_standard_deviation <- sd(okcupid_data)
#IGNORE CODE BELOW HERE
print(paste("The standard deviation of the NBA dataset is ",nba_standard_deviation))
print(paste("The standard deviation of the OkCupid dataset is ", okcupid_standard_deviation))
```
Codecademy Standard Deviation in R Standard Deviation 2/5
#Sample Solution
---
title: "Standard Deviation"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(tidyr)
```
```{r}
# Importing data and calculating variance
load("lesson_data.Rda")
variance <- function(x) mean((x-mean(x))^2)
nba_variance <- variance(nba_data)
okcupid_variance <- variance(okcupid_data)
```
```{r}
# Change these variables to be the standard deviation of each dataset.
nba_standard_deviation <- nba_variance ^ 0.5
okcupid_standard_deviation <- okcupid_variance ^ 0.5
#IGNORE CODE BELOW HERE
print(paste("The standard deviation of the NBA dataset is ",nba_standard_deviation))
print(paste("The standard deviation of the OkCupid dataset is ", okcupid_standard_deviation))
```
---
title: "Standard Deviation"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(tidyr)
```
```{r}
# Importing data and calculating variance
load("lesson_data.Rda")
variance <- function(x) mean((x-mean(x))^2)
nba_variance <- variance(nba_data)
okcupid_variance <- variance(okcupid_data)
```
```{r}
# Change these variables to be the standard deviation of each dataset.
nba_standard_deviation <- nba_variance ^ 0.5
okcupid_standard_deviation <- okcupid_variance ^ 0.5
#IGNORE CODE BELOW HERE
print(paste("The standard deviation of the NBA dataset is ",nba_standard_deviation))
print(paste("The standard deviation of the OkCupid dataset is ", okcupid_standard_deviation))
```
Codecademy Variance in R 5/6
#Sample Solution
---
title: "Variance in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
#defining the variance of the population mean
variance <- function(x) mean((x-mean(x))^2)
teacher_one_grades <- c(80.24, 81.15, 81.29, 82.12, 82.52, 82.54, 82.76, 83.37, 83.42, 83.45, 83.47, 83.79, 83.91, 83.98, 84.03, 84.69, 84.74, 84.89, 84.95, 84.95, 85.02, 85.18, 85.53, 86.29, 86.83, 87.29, 87.47, 87.62, 88.04, 88.5)
teacher_two_grades <- c(65.82, 70.77, 71.46, 73.63, 74.62, 76.53, 76.86, 77.06, 78.46, 79.81, 80.64, 81.61, 81.84, 83.67, 84.44, 84.73, 84.74, 85.15, 86.55, 88.06, 88.53, 90.12, 91.27, 91.62, 92.86, 94.37, 95.64, 95.99, 97.69, 104.4)
#Set these two variables equal to the variance of each dataset using NumPy
teacher_one_grades
teacher_two_grades
teacher_one_variance <- variance(teacher_one_grades)
teacher_two_variance <- variance(teacher_two_grades)
#IGNORE THE CODE BELOW HERE
hist(teacher_one_grades, col=rgb(0,0,1,1/4),xlim=c(65,105), main="Teacher Grades One and Two", breaks=15)
hist(teacher_two_grades, col=rgb(1,0,0,1/4), add=T, breaks=15)
legend("topright", c("Teacher 1", "Teacher 2"), fill=c("blue", "red"))
box()
print(paste("The mean of the test scores in teacher one's class is ", mean(teacher_one_grades)))
print(paste("The mean of the test scores in teacher two's class is ", mean(teacher_two_grades)))
print(paste("The variance of the test scores in teacher one's class is ", teacher_one_variance))
print(paste("The variance of the test scores in teacher two's class is ", teacher_two_variance))
```
---
title: "Variance in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
#defining the variance of the population mean
variance <- function(x) mean((x-mean(x))^2)
teacher_one_grades <- c(80.24, 81.15, 81.29, 82.12, 82.52, 82.54, 82.76, 83.37, 83.42, 83.45, 83.47, 83.79, 83.91, 83.98, 84.03, 84.69, 84.74, 84.89, 84.95, 84.95, 85.02, 85.18, 85.53, 86.29, 86.83, 87.29, 87.47, 87.62, 88.04, 88.5)
teacher_two_grades <- c(65.82, 70.77, 71.46, 73.63, 74.62, 76.53, 76.86, 77.06, 78.46, 79.81, 80.64, 81.61, 81.84, 83.67, 84.44, 84.73, 84.74, 85.15, 86.55, 88.06, 88.53, 90.12, 91.27, 91.62, 92.86, 94.37, 95.64, 95.99, 97.69, 104.4)
#Set these two variables equal to the variance of each dataset using NumPy
teacher_one_grades
teacher_two_grades
teacher_one_variance <- variance(teacher_one_grades)
teacher_two_variance <- variance(teacher_two_grades)
#IGNORE THE CODE BELOW HERE
hist(teacher_one_grades, col=rgb(0,0,1,1/4),xlim=c(65,105), main="Teacher Grades One and Two", breaks=15)
hist(teacher_two_grades, col=rgb(1,0,0,1/4), add=T, breaks=15)
legend("topright", c("Teacher 1", "Teacher 2"), fill=c("blue", "red"))
box()
print(paste("The mean of the test scores in teacher one's class is ", mean(teacher_one_grades)))
print(paste("The mean of the test scores in teacher two's class is ", mean(teacher_two_grades)))
print(paste("The variance of the test scores in teacher one's class is ", teacher_one_variance))
print(paste("The variance of the test scores in teacher two's class is ", teacher_two_variance))
```
Codecademy Variance in R Square the Differences 4/6
#Sample Solution
---
title: "Variance in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
grades <- c(88, 82, 85, 84, 90)
mean <- mean(grades)
#Change these five variables
difference_one <- (88 - mean) ^ 2
difference_two <- (82 - mean) ^ 2
difference_three <- (85 - mean) ^ 2
difference_four <- (84 - mean) ^ 2
difference_five <- (90 - mean) ^ 2
#Part 1: Sum the differences
difference_sum <- difference_one + difference_two + difference_three + difference_four + difference_five
#Part 2: Average the differences
variance <- difference_sum / 5
#IGNORE CODE BELOW HERE
print(paste("The sum of the differences is ", format(difference_sum, scientific = FALSE )))
print(paste("The variance difference is " , format(variance, scientific = FALSE)))
```
---
title: "Variance in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
grades <- c(88, 82, 85, 84, 90)
mean <- mean(grades)
#Change these five variables
difference_one <- (88 - mean) ^ 2
difference_two <- (82 - mean) ^ 2
difference_three <- (85 - mean) ^ 2
difference_four <- (84 - mean) ^ 2
difference_five <- (90 - mean) ^ 2
#Part 1: Sum the differences
difference_sum <- difference_one + difference_two + difference_three + difference_four + difference_five
#Part 2: Average the differences
variance <- difference_sum / 5
#IGNORE CODE BELOW HERE
print(paste("The sum of the differences is ", format(difference_sum, scientific = FALSE )))
print(paste("The variance difference is " , format(variance, scientific = FALSE)))
```
Codecademy Variance in R Average Distances 3/6
#Sample Solution
---
title: "Variance in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
grades <- c(88, 82, 85, 84, 90)
mean <- mean(grades)
difference_one <- 88 - mean
difference_two <- 82 - mean
difference_three <- 85 - mean
difference_four <- 84 - mean
difference_five <- 90 - mean
#Part 1: Sum the differences
difference_sum <- difference_one + difference_two + difference_three + difference_four + difference_five
#Part 2: Average the differences
average_difference <- difference_sum / 5
#IGNORE CODE BELOW HERE
print(paste("The sum of the differences is ", format(difference_sum, scientific = FALSE )))
print(paste("The average difference is " , format(average_difference, scientific = FALSE)))
```
---
title: "Variance in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
grades <- c(88, 82, 85, 84, 90)
mean <- mean(grades)
difference_one <- 88 - mean
difference_two <- 82 - mean
difference_three <- 85 - mean
difference_four <- 84 - mean
difference_five <- 90 - mean
#Part 1: Sum the differences
difference_sum <- difference_one + difference_two + difference_three + difference_four + difference_five
#Part 2: Average the differences
average_difference <- difference_sum / 5
#IGNORE CODE BELOW HERE
print(paste("The sum of the differences is ", format(difference_sum, scientific = FALSE )))
print(paste("The average difference is " , format(average_difference, scientific = FALSE)))
```
Codecademy Variance in R Distance From Mean 2/6
#Sample Solution
---
title: "Variance in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load data
grades <- c(88, 82, 85, 84, 90)
mean <- mean(grades)
#Change these five variables
difference_one <- 88 - mean
difference_two <- 82 - mean
difference_three <- 85 - mean
difference_four <- 84 - mean
difference_five <- 90 - mean
print(paste("The mean of the data set is ", mean))
print(paste("The first student is", round(difference_one, digits=2) , "percentage points away from the mean."))
print(paste("The second student is ", round(difference_two, digits=2) , "percentage points away from the mean."))
print(paste("The third student is",round(difference_three, digits=2) , "percentage points away from the mean."))
print(paste("The fourth student is",round(difference_four, digits=2) , "percentage points away from the mean."))
print(paste("The fifth student is",round(difference_five, digits=2) , "percentage points away from the mean."))
```
---
title: "Variance in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load data
grades <- c(88, 82, 85, 84, 90)
mean <- mean(grades)
#Change these five variables
difference_one <- 88 - mean
difference_two <- 82 - mean
difference_three <- 85 - mean
difference_four <- 84 - mean
difference_five <- 90 - mean
print(paste("The mean of the data set is ", mean))
print(paste("The first student is", round(difference_one, digits=2) , "percentage points away from the mean."))
print(paste("The second student is ", round(difference_two, digits=2) , "percentage points away from the mean."))
print(paste("The third student is",round(difference_three, digits=2) , "percentage points away from the mean."))
print(paste("The fourth student is",round(difference_four, digits=2) , "percentage points away from the mean."))
print(paste("The fifth student is",round(difference_five, digits=2) , "percentage points away from the mean."))
```
Codecademy Mode in R Mode with DescTools 3/4
#Sample Solution
---
title: "Mode in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# import libraries
library(readr)
library(dplyr)
library(DescTools)
# Read author data
greatest_books = read_csv("top-hundred-books.csv")
# Set author ages to
author_ages <- greatest_books$Ages
mode_age <- Mode(author_ages)
print(paste("The mode age of authors from Le Monde's 100 greatest books is: ", mode_age[1]))
```
---
title: "Mode in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# import libraries
library(readr)
library(dplyr)
library(DescTools)
# Read author data
greatest_books = read_csv("top-hundred-books.csv")
# Set author ages to
author_ages <- greatest_books$Ages
mode_age <- Mode(author_ages)
print(paste("The mode age of authors from Le Monde's 100 greatest books is: ", mode_age[1]))
```
Codecademy Mode in R 2/4
#Sample Solution
---
title: "Mean in R"
output: html_notebook
---
```{r}
#29:1, 49:1, 42:1, 43:1, 32:1, 41:1, 27:2
mode_age <- 27
mode_count <- 2
```
---
title: "Mean in R"
output: html_notebook
---
```{r}
#29:1, 49:1, 42:1, 43:1, 32:1, 41:1, 27:2
mode_age <- 27
mode_count <- 2
```
Codecademy Median in R 3/4
#Sample Solution
---
title: "Median in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
# Load data frame
greatest_books <- read_csv('top-hundred-books.csv')
# Save author ages to author_ages
author_ages <- greatest_books$Ages
# Use R to calculate the median age of the top 100 authors
median_age <- median(author_ages)
print(paste("The median age of the 100 greatest authors, according to a survey by Le Monde is: " , median_age))
```
---
title: "Median in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
# Load data frame
greatest_books <- read_csv('top-hundred-books.csv')
# Save author ages to author_ages
author_ages <- greatest_books$Ages
# Use R to calculate the median age of the top 100 authors
median_age <- median(author_ages)
print(paste("The median age of the 100 greatest authors, according to a survey by Le Monde is: " , median_age))
```
Codecademy Median in R 2/4
#Sample Solution
---
title: "Median in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
# Array of the first five author ages
five_author_ages <- c(29, 49, 42, 43, 32)
# Fill in the empty array with the values sorted
sorted_author_ages <- c(29, 32, 42, 43, 49)
# Save the median value to median_value
median_value <- 42
# Print the sorted array and median value
cat("The sorted array is:", sorted_author_ages)
cat(paste("The median of the array is: ", median_value))
```
---
title: "Median in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
# Array of the first five author ages
five_author_ages <- c(29, 49, 42, 43, 32)
# Fill in the empty array with the values sorted
sorted_author_ages <- c(29, 32, 42, 43, 49)
# Save the median value to median_value
median_value <- 42
# Print the sorted array and median value
cat("The sorted array is:", sorted_author_ages)
cat(paste("The median of the array is: ", median_value))
```
Codecademy Mean in R 3/4
#Sample Solution
---
title: "Mean in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# import libraries
library(readr)
library(dplyr)
# Read author data
greatest_books = read_csv("top-hundred-books.csv")
# Set author ages to a vector
author_ages <- greatest_books$Ages
# Use R to calculate mean
average_age <- mean(author_ages)
print(average_age)
```
---
title: "Mean in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# import libraries
library(readr)
library(dplyr)
# Read author data
greatest_books = read_csv("top-hundred-books.csv")
# Set author ages to a vector
author_ages <- greatest_books$Ages
# Use R to calculate mean
average_age <- mean(author_ages)
print(average_age)
```
Codecademy Mean in R Calculating Mean 2/4
#Sample Solution
---
title: "Mean in R"
output: html_notebook
---
```{r}
total <- 29 + 49 + 42 + 43
print(total)
mean_value <- total / 4
print(mean_value)
```
---
title: "Mean in R"
output: html_notebook
---
```{r}
total <- 29 + 49 + 42 + 43
print(total)
mean_value <- total / 4
print(mean_value)
```
Codecademy Joining Tables in R Review 11/11
# Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load visits and checkouts data
visits <- read_csv('visits.csv')
checkouts <- read_csv('checkouts.csv')
```
```{r}
# inspect visits and checkouts here:
head(visits)
head(checkouts)
```
```{r}
# define v_to_c here:
v_to_c <- visits %>% inner_join(checkouts)
v_to_c
v_to_c <- v_to_c %>% mutate(time = checkout_time - visit_time)
v_to_c
```
```{r}
# define avg_time_to_check here:
avg_time_to_check <- v_to_c %>% summarize(mean_time = mean(time))
avg_time_to_check
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load visits and checkouts data
visits <- read_csv('visits.csv')
checkouts <- read_csv('checkouts.csv')
```
```{r}
# inspect visits and checkouts here:
head(visits)
head(checkouts)
```
```{r}
# define v_to_c here:
v_to_c <- visits %>% inner_join(checkouts)
v_to_c
v_to_c <- v_to_c %>% mutate(time = checkout_time - visit_time)
v_to_c
```
```{r}
# define avg_time_to_check here:
avg_time_to_check <- v_to_c %>% summarize(mean_time = mean(time))
avg_time_to_check
```
Codecademy Joining Tables in R Concatenate Data Frames 10/11
#Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load bakery and ice_cream data
bakery <- read_csv('bakery.csv')
ice_cream <- read_csv('ice_cream.csv')
```
```{r}
# inspect bakery and ice_cream
head(bakery)
head(ice_cream)
```
```{r}
# define menu here:
menu <- bakery %>% bind_rows(ice_cream)
menu
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load bakery and ice_cream data
bakery <- read_csv('bakery.csv')
ice_cream <- read_csv('ice_cream.csv')
```
```{r}
# inspect bakery and ice_cream
head(bakery)
head(ice_cream)
```
```{r}
# define menu here:
menu <- bakery %>% bind_rows(ice_cream)
menu
```
Codecademy Joining Tables in R Left and Right Joins 9/11
#Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load store_a and store_b data
store_a <- read_csv("store_a.csv")
store_b <- read_csv("store_b.csv")
```
```{r}
# inspect store_a and store_b
head(store_a)
head(store_b)
```
```{r}
# define left_a_b here:
left_a_b <- store_a %>% left_join(store_b)
left_a_b
```
```{r}
# define left_b_a here:
left_b_a <- store_b %>% left_join(store_a)
left_b_a
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load store_a and store_b data
store_a <- read_csv("store_a.csv")
store_b <- read_csv("store_b.csv")
```
```{r}
# inspect store_a and store_b
head(store_a)
head(store_b)
```
```{r}
# define left_a_b here:
left_a_b <- store_a %>% left_join(store_b)
left_a_b
```
```{r}
# define left_b_a here:
left_b_a <- store_b %>% left_join(store_a)
left_b_a
```
Codecademy Joining Tables in R Full Join 8/11
#Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load store_a and store_b data
store_a <- read_csv("store_a.csv")
store_b <- read_csv("store_b.csv")
```
```{r}
# inspect store_a and store_b
head(store_a)
head(store_b)
```
```{r}
# define store_a_b_full here:
store_a_b_full <- store_a %>% full_join(store_b)
store_a_b_full
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load store_a and store_b data
store_a <- read_csv("store_a.csv")
store_b <- read_csv("store_b.csv")
```
```{r}
# inspect store_a and store_b
head(store_a)
head(store_b)
```
```{r}
# define store_a_b_full here:
store_a_b_full <- store_a %>% full_join(store_b)
store_a_b_full
```
Codecademy Joining Tables in R Mismatched Joins 7/11
#Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders and products data
orders <- read_csv("orders.csv")
products <- read_csv("products.csv")
```
```{r}
# inspect orders and products here:
head(orders)
head(products)
```
```{r}
# define orders_products here:
orders_products <- orders %>% inner_join(products)
orders_products #order_id 3 is missing
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders and products data
orders <- read_csv("orders.csv")
products <- read_csv("products.csv")
```
```{r}
# inspect orders and products here:
head(orders)
head(products)
```
```{r}
# define orders_products here:
orders_products <- orders %>% inner_join(products)
orders_products #order_id 3 is missing
```
Codecademy Joining Tables in R Join on Specific Columns II 6/11
#Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders and products data
orders <- read_csv("orders.csv")
products <- read_csv("products.csv")
```
```{r}
# inspect orders and products
head(orders)
head(products)
```
```{r}
# define orders_products here:
orders_products <- orders %>% inner_join(products, by = c('product_id' = 'id'))
orders_products
```
```{r}
# define products_orders here:
products_orders <- products %>% inner_join(orders, by = c('id' = 'product_id'), suffix = c('_product','_order'))
products_orders
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders and products data
orders <- read_csv("orders.csv")
products <- read_csv("products.csv")
```
```{r}
# inspect orders and products
head(orders)
head(products)
```
```{r}
# define orders_products here:
orders_products <- orders %>% inner_join(products, by = c('product_id' = 'id'))
orders_products
```
```{r}
# define products_orders here:
products_orders <- products %>% inner_join(orders, by = c('id' = 'product_id'), suffix = c('_product','_order'))
products_orders
```
Codecademy Joining Tables in R Join on Specific Columns I 5/11
#Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders and products data
orders <- read_csv("orders.csv")
products <- read_csv("products.csv")
```
```{r}
# inspect orders and products
head(orders)
head(products)
```
```{r}
# rename the id column of products here:
products <- products %>% rename(product_id = id)
products
```
```{r}
# define orders_products here:
orders_products <- orders %>% inner_join(products)
orders_products
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders and products data
orders <- read_csv("orders.csv")
products <- read_csv("products.csv")
```
```{r}
# inspect orders and products
head(orders)
head(products)
```
```{r}
# rename the id column of products here:
products <- products %>% rename(product_id = id)
products
```
```{r}
# define orders_products here:
orders_products <- orders %>% inner_join(products)
orders_products
```
Codecademy Joining Tables in R Inner Join II 4/11
#Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load and inspect sales and targets data
sales <- read_csv("sales.csv")
targets <- read_csv("targets.csv")
head(sales)
head(targets)
```
```{r}
# load men_women data here:
men_women <- read_csv('men_women_sales.csv')
# inspect men_women here:
head(men_women)
```
```{r}
# define all_data here:
all_data <- sales %>% inner_join(targets) %>% inner_join(men_women)
all_data
```
```{r}
# define results here:
results <- all_data %>% filter(revenue > target, women > men)
results
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load and inspect sales and targets data
sales <- read_csv("sales.csv")
targets <- read_csv("targets.csv")
head(sales)
head(targets)
```
```{r}
# load men_women data here:
men_women <- read_csv('men_women_sales.csv')
# inspect men_women here:
head(men_women)
```
```{r}
# define all_data here:
all_data <- sales %>% inner_join(targets) %>% inner_join(men_women)
all_data
```
```{r}
# define results here:
results <- all_data %>% filter(revenue > target, women > men)
results
```
Codecademy Joining Tables in R Inner Join I 3/11
#Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load sales and targets data
sales <- read_csv("sales.csv")
targets <- read_csv("targets.csv")
```
```{r}
# inspect orders, customers and products
head(sales)
head(targets)
```
```{r}
# define sales_vs_targets here:
sales_vs_targets <- sales %>% inner_join(targets)
sales_vs_targets
```
```{r}
# define crushing_it here:
crushing_it <- sales_vs_targets %>% filter(revenue > target)
crushing_it
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load sales and targets data
sales <- read_csv("sales.csv")
targets <- read_csv("targets.csv")
```
```{r}
# inspect orders, customers and products
head(sales)
head(targets)
```
```{r}
# define sales_vs_targets here:
sales_vs_targets <- sales %>% inner_join(targets)
sales_vs_targets
```
```{r}
# define crushing_it here:
crushing_it <- sales_vs_targets %>% filter(revenue > target)
crushing_it
```
Codecademy Joining Tables in R Joining 2/11
#Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
customers <- read_csv("customers.csv")
products <- read_csv("products.csv")
```
```{r}
# inspect orders, customers and products
head(orders)
head(customers)
head(products)
```
```{r}
# define order_3_description here:
order_3_description <- 'thing-a-ma-jig'
# define order_5_phone_number here:
order_5_phone_number <- '112-358-1321'
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
customers <- read_csv("customers.csv")
products <- read_csv("products.csv")
```
```{r}
# inspect orders, customers and products
head(orders)
head(customers)
head(products)
```
```{r}
# define order_3_description here:
order_3_description <- 'thing-a-ma-jig'
# define order_5_phone_number here:
order_5_phone_number <- '112-358-1321'
```
Codecademy Joining Tables in R Introduction 1/11
#Sample Solution
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
customers <- read_csv("customers.csv")
products <- read_csv("products.csv")
```
```{r}
# inspect orders, customers and products here:
head(orders)
head(products)
head(customers)
```
---
title: "Joining Tables in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
customers <- read_csv("customers.csv")
products <- read_csv("products.csv")
```
```{r}
# inspect orders, customers and products here:
head(orders)
head(products)
head(customers)
```
Codecademy Aggregates in R Combining Grouping with Mutate 6/7
#Sample Solution
---
title: "Aggregates in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
# inspect orders
head(orders)
```
```{r}
# define diff_from_mean here:
diff_from_mean <- orders %>% group_by(shoe_type) %>% mutate(diff_from_shoe_type_mean=price-mean(price,na.rm=TRUE))
diff_from_mean
```
---
title: "Aggregates in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
# inspect orders
head(orders)
```
```{r}
# define diff_from_mean here:
diff_from_mean <- orders %>% group_by(shoe_type) %>% mutate(diff_from_shoe_type_mean=price-mean(price,na.rm=TRUE))
diff_from_mean
```
Codecademy Aggregates in R Combining Grouping with Filter 5/7
#Sample Solution
---
title: "Aggregates in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
# inspect orders
head(orders)
```
```{r}
# define most_pop_orders here:
most_pop_orders <- orders %>%
group_by(shoe_type) %>%
filter(n() > 16)
most_pop_orders
```
---
title: "Aggregates in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
# inspect orders
head(orders)
```
```{r}
# define most_pop_orders here:
most_pop_orders <- orders %>%
group_by(shoe_type) %>%
filter(n() > 16)
most_pop_orders
```
Codecademy Aggregates in R Calculating Aggregate Functions II 4/7
#Sample Solution
---
title: "Aggregates in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
# inspect orders
head(orders)
```
```{r}
# define shoe_counts here:
shoe_counts <- orders %>% group_by(shoe_type,shoe_color) %>% summarize(shoe_counts=n())
shoe_counts
```
```{r}
# define shoe_prices here:
shoe_prices <- orders %>% group_by(shoe_type,shoe_material) %>% summarize(shoe_prices=mean(price, na.rm=TRUE))
shoe_prices
```
---
title: "Aggregates in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
# inspect orders
head(orders)
```
```{r}
# define shoe_counts here:
shoe_counts <- orders %>% group_by(shoe_type,shoe_color) %>% summarize(shoe_counts=n())
shoe_counts
```
```{r}
# define shoe_prices here:
shoe_prices <- orders %>% group_by(shoe_type,shoe_material) %>% summarize(shoe_prices=mean(price, na.rm=TRUE))
shoe_prices
```
Codecademy Aggregates in R Calculating Aggregate Functions I 3/7
#Sample Solution
---
title: "Aggregates in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
# inspect orders
head(orders)
```
```{r}
# define pricey_shoes here:
pricey_shoes <- orders %>% group_by(shoe_type) %>% summarize(pricey_shoes=max(price,na.rm=TRUE))
pricey_shoes
```
```{r}
# define shoes_sold here:
shoes_sold <- orders %>% group_by(shoe_type) %>% summarize(shoes_sold=n())
shoes_sold
```
---
title: "Aggregates in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load orders data
orders <- read_csv("orders.csv")
# inspect orders
head(orders)
```
```{r}
# define pricey_shoes here:
pricey_shoes <- orders %>% group_by(shoe_type) %>% summarize(pricey_shoes=max(price,na.rm=TRUE))
pricey_shoes
```
```{r}
# define shoes_sold here:
shoes_sold <- orders %>% group_by(shoe_type) %>% summarize(shoes_sold=n())
shoes_sold
```
Codecademy Aggregates in R Calculating Column Statistics 2/7
#Sample Solution
---
title: "Aggregates in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load order data
orders <- read_csv("orders.csv")
# inspect orders here:
head(orders,10)
```
```{r}
# define most_expensive here:
most_expensive <- orders %>% summarize(most_expensive = max(price, na.rm=TRUE))
print(most_expensive)
```
```{r}
# define num_colors here:
num_colors <- orders %>% summarize(num_colors = n_distinct(shoe_color))
#print(num_colors)
#orders %>% distinct(shoe_color) %>% select(shoe_color) %>% arrange(shoe_color)
```
---
title: "Aggregates in R"
output: html_notebook
---
```{r message = FALSE}
# load packages
library(readr)
library(dplyr)
```
```{r message = FALSE}
# load order data
orders <- read_csv("orders.csv")
# inspect orders here:
head(orders,10)
```
```{r}
# define most_expensive here:
most_expensive <- orders %>% summarize(most_expensive = max(price, na.rm=TRUE))
print(most_expensive)
```
```{r}
# define num_colors here:
num_colors <- orders %>% summarize(num_colors = n_distinct(shoe_color))
#print(num_colors)
#orders %>% distinct(shoe_color) %>% select(shoe_color) %>% arrange(shoe_color)
```
Wednesday, September 4, 2019
Codecademy Intro to Visualization with R Extending The Grammar 10/11
#Sample Solution
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
```
```{r}
# Inspect the mpg builtin dataset
head(mpg)
```
```{r message=FALSE}
#Create a bar chart
bar <- ggplot(mpg, aes(class)) + geom_bar(aes(fill=class)) +
labs(title="Types of Vehicles", subtitle="From fuel economy data for popular car models (1999-2008)")
bar
```
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
```
```{r}
# Inspect the mpg builtin dataset
head(mpg)
```
```{r message=FALSE}
#Create a bar chart
bar <- ggplot(mpg, aes(class)) + geom_bar(aes(fill=class)) +
labs(title="Types of Vehicles", subtitle="From fuel economy data for popular car models (1999-2008)")
bar
```
Codecademy Intro to Visualization with R Labels 9/11
#Sample Solution
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
# Add labels as specified
viz <- ggplot(data=movies, aes(x=imdbRating, y=nrOfWins)) +
geom_point(aes(color=nrOfGenre), alpha=0.5) + labs(title='Movie Ratings Vs Award Wins',subtitle='From IMDB dataset',x='Movie Rating',y='Number of Award Wins', color='Number of Genre')
# Prints the plot
viz
```
```{r message=FALSE}
```
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
# Add labels as specified
viz <- ggplot(data=movies, aes(x=imdbRating, y=nrOfWins)) +
geom_point(aes(color=nrOfGenre), alpha=0.5) + labs(title='Movie Ratings Vs Award Wins',subtitle='From IMDB dataset',x='Movie Rating',y='Number of Award Wins', color='Number of Genre')
# Prints the plot
viz
```
```{r message=FALSE}
```
Codecademy Intro to Visualization with R Manual Aesthetics 8/11
#Sample Solution
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
# Add manual alpha aesthetic mapping
viz <- ggplot(data=movies, aes(x=imdbRating, y=nrOfWins)) +
geom_point(aes(color=nrOfGenre), alpha=.5)
# Prints the plot
viz
```
```{r message=FALSE}
```
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
# Add manual alpha aesthetic mapping
viz <- ggplot(data=movies, aes(x=imdbRating, y=nrOfWins)) +
geom_point(aes(color=nrOfGenre), alpha=.5)
# Prints the plot
viz
```
```{r message=FALSE}
```
Codecademy Intro to Visualization with R Geom Aesthetics 7/11
#Sample Solution
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
# Add manual alpha aesthetic mapping
viz <- ggplot(data=movies, aes(x=imdbRating, y=nrOfWins)) + geom_point(aes(color=nrOfGenre))
# Prints the plot
viz
```
```{r message=FALSE}
```
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
# Add manual alpha aesthetic mapping
viz <- ggplot(data=movies, aes(x=imdbRating, y=nrOfWins)) + geom_point(aes(color=nrOfGenre))
# Prints the plot
viz
```
```{r message=FALSE}
```
Codecademy Intro to Visualization with R Adding Geoms 6/11
#Sample Solution
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
# Add a geom point layer
viz <- ggplot(data=movies, aes(x=imdbRating, y=nrOfWins)) + geom_point()
# Prints the plot
viz
```
```{r message=FALSE}
```
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
# Add a geom point layer
viz <- ggplot(data=movies, aes(x=imdbRating, y=nrOfWins)) + geom_point()
# Prints the plot
viz
```
```{r message=FALSE}
```
Codecademy Intro to Visualization with R What are aesthetics? 5/11
#Sample Solution
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
#Create aesthetic mappings at the canvas level
viz <- ggplot(data=movies, aes(x=imdbRating,y=nrOfWins))
viz
```
```{r message=FALSE}
```
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
#Create aesthetic mappings at the canvas level
viz <- ggplot(data=movies, aes(x=imdbRating,y=nrOfWins))
viz
```
```{r message=FALSE}
```
Codecademy Intro to Visualization with R Associating the Data 4/11
#Sample Solution
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
#Define variable and print it
viz <- ggplot(movies)
viz
```
```{r message=FALSE}
```
---
title: "Intro To GGPlot2"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries and data
library(readr)
library(dplyr)
library(ggplot2)
movies <- read_csv("imdb.csv")
```
```{r}
#Define variable and print it
viz <- ggplot(movies)
viz
```
```{r message=FALSE}
```
Codecademy Learn R Review 10/10
#Sample Solution
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# view head of students
head(students)
```
```{r}
# update age column
students <- students %>% mutate(age = as.numeric(age))
students
```
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# view head of students
head(students)
```
```{r}
# update age column
students <- students %>% mutate(age = as.numeric(age))
students
```
Codecademy Learn R String Parsing 9/10
#Sample Solution
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# view head of students
head(students)
```
```{r}
# remove % from score column
students <- students %>% mutate(score=gsub('\\%','',score))
students
```
```{r}
# change score column to numeric
students <- students %>% mutate(score = as.numeric(score))
students
```
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# view head of students
head(students)
```
```{r}
# remove % from score column
students <- students %>% mutate(score=gsub('\\%','',score))
students
```
```{r}
# change score column to numeric
students <- students %>% mutate(score = as.numeric(score))
students
```
Codecademy Learn R Looking at Data Types 8/10
#Sample Solution
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# print structure of students
str(students)
```
```{r}
# mean of age column
students %>% summarise(mean_score = mean(score))
# warning: argument is not numeric or logical
```
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# print structure of students
str(students)
```
```{r}
# mean of age column
students %>% summarise(mean_score = mean(score))
# warning: argument is not numeric or logical
```
Codecademy Learn R Splitting By Character 7/10
#Sample Solution
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(tidyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# view the head of students
head(students)
```
```{r}
# separate the full_name column
students <- students %>% separate(full_name,c('first_name','last_name'),' ',extra='merge')
head(students)
```
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(tidyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# view the head of students
head(students)
```
```{r}
# separate the full_name column
students <- students %>% separate(full_name,c('first_name','last_name'),' ',extra='merge')
head(students)
```
Codecademy Learn R Splitting By Index 6/10
#Sample Solution
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(stringr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# print columns of students
print(colnames(students))
```
```{r}
# view head of students
head(students)
```
```{r}
# add gender and age columns
students <- students %>%
mutate(gender = str_sub(gender_age,1,1),
age = str_sub(gender_age,2))
head(students)
```
```{r}
# drop gender_age column
students <- students %>%
select(-gender_age)
head(students)
```
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(stringr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# print columns of students
print(colnames(students))
```
```{r}
# view head of students
head(students)
```
```{r}
# add gender and age columns
students <- students %>%
mutate(gender = str_sub(gender_age,1,1),
age = str_sub(gender_age,2))
head(students)
```
```{r}
# drop gender_age column
students <- students %>%
select(-gender_age)
head(students)
```
Codecademy Learn R Dealing with Duplicates 5/10
#Sample Solution
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(tidyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# drop id column
students <- students %>% select(-id)
head(students)
```
```{r}
# find and count duplicated rows
duplicates <- students %>% duplicated()
duplicates <- duplicates %>% table()
duplicates
```
```{r}
# remove duplicated rows
students <- students %>% distinct()
```
```{r}
# find and count duplicated rows in updated data frame
updated_duplicates <- students %>% duplicated()
updated_duplicates <- updated_duplicates %>% table()
updated_duplicates
```
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(tidyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# drop id column
students <- students %>% select(-id)
head(students)
```
```{r}
# find and count duplicated rows
duplicates <- students %>% duplicated()
duplicates <- duplicates %>% table()
duplicates
```
```{r}
# remove duplicated rows
students <- students %>% distinct()
```
```{r}
# find and count duplicated rows in updated data frame
updated_duplicates <- students %>% duplicated()
updated_duplicates <- updated_duplicates %>% table()
updated_duplicates
```
Codecademy Learn R Reshaping your Data 4/10
#Sample Solution
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(tidyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# original column names
students
original_col_names <- colnames(students)
original_col_names
```
```{r}
# gather columns
students <- students %>% gather('fractions','probability',key='exam',value='score')
head(students)
```
```{r}
# updated column names
gathered_col_names <- colnames(students)
gathered_col_names
```
```{r}
# unique value counts of exam
exam_counts <- students %>% count(exam)
exam_counts
```
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(dplyr)
library(tidyr)
```
```{r}
# load students data frame
load("students.Rda")
```
```{r}
# original column names
students
original_col_names <- colnames(students)
original_col_names
```
```{r}
# gather columns
students <- students %>% gather('fractions','probability',key='exam',value='score')
head(students)
```
```{r}
# updated column names
gathered_col_names <- colnames(students)
gathered_col_names
```
```{r}
# unique value counts of exam
exam_counts <- students %>% count(exam)
exam_counts
```
Codecademy Learn R Dealing with Multiple Files 3/10
#Sample Solution
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r}
# list files
student_files <- list.files(pattern = "exams_.*csv")
```
```{r message=FALSE}
# read files
df_list <- lapply(student_files,read_csv)
```
```{r}
# concatenate data frames
students <- bind_rows(df_list)
students
```
```{r}
# number of rows in students
nrow_students <- 1000
```
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r}
# list files
student_files <- list.files(pattern = "exams_.*csv")
```
```{r message=FALSE}
# read files
df_list <- lapply(student_files,read_csv)
```
```{r}
# concatenate data frames
students <- bind_rows(df_list)
students
```
```{r}
# number of rows in students
nrow_students <- 1000
```
Codecademy Learn R Diagnose the Data 2/10
#Sample Solution
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# read CSVs
grocery_1 <- read_csv('grocery_1.csv')
grocery_2 <- read_csv('grocery_2.csv')
```
```{r}
# inspect data frames
head(grocery_1)
head(grocery_2)
summary(grocery_1)
summary(grocery_2)
colnames(grocery_1)
colnames(grocery_2)
```
```{r}
# clean data frame
clean_data_frame <- 2
```
---
title: "Data Cleaning in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# read CSVs
grocery_1 <- read_csv('grocery_1.csv')
grocery_2 <- read_csv('grocery_2.csv')
```
```{r}
# inspect data frames
head(grocery_1)
head(grocery_2)
summary(grocery_1)
summary(grocery_2)
colnames(grocery_1)
colnames(grocery_2)
```
```{r}
# clean data frame
clean_data_frame <- 2
```
Codecademy Learn R Review 6/6
#Sample Solution
---
title: "Modifying Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```
```{r}
# inspect data frame
head(dogs)
```
```{r}
# add new columns, drop existing columns and arrange
dogs <- dogs %>% transmute(breed = breed, height_average_feet =(height_low_inches + height_high_inches)/24, popularity_change_15_to_16 = rank_2016 - rank_2015) %>% arrange(desc(popularity_change_15_to_16))
head(dogs)
```
---
title: "Modifying Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```
```{r}
# inspect data frame
head(dogs)
```
```{r}
# add new columns, drop existing columns and arrange
dogs <- dogs %>% transmute(breed = breed, height_average_feet =(height_low_inches + height_high_inches)/24, popularity_change_15_to_16 = rank_2016 - rank_2015) %>% arrange(desc(popularity_change_15_to_16))
head(dogs)
```
Codecademy Learn R Rename Columns 5/6
#Sample Solution
---
title: "Modifying Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```
```{r message=FALSE}
# add columns and remove existing columns
dogs <- dogs %>%
transmute(breed = breed,
avg_height = (height_low_inches + height_high_inches)/2,
avg_weight = (weight_low_lbs + weight_high_lbs)/2,
rank_change_13_to_16 = rank_2016 - rank_2013)
```
```{r}
# check column names
original_col_names <- colnames(dogs)
print(original_col_names)
```
```{r}
# rename data frame columns
dogs <- dogs %>%
rename(avg_height_inches = avg_height, avg_weight_lbs = avg_weight, popularity_change_13_to_16 = rank_change_13_to_16)
```
```{r}
# check column names
new_col_names <- colnames(dogs)
print(new_col_names)
```
---
title: "Modifying Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```
```{r message=FALSE}
# add columns and remove existing columns
dogs <- dogs %>%
transmute(breed = breed,
avg_height = (height_low_inches + height_high_inches)/2,
avg_weight = (weight_low_lbs + weight_high_lbs)/2,
rank_change_13_to_16 = rank_2016 - rank_2013)
```
```{r}
# check column names
original_col_names <- colnames(dogs)
print(original_col_names)
```
```{r}
# rename data frame columns
dogs <- dogs %>%
rename(avg_height_inches = avg_height, avg_weight_lbs = avg_weight, popularity_change_13_to_16 = rank_change_13_to_16)
```
```{r}
# check column names
new_col_names <- colnames(dogs)
print(new_col_names)
```
Codecademy Learn R Transmute Columns 4/6
#Sample Solution
---
title: "Modifying Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```
```{r}
# inspect data frame
head(dogs)
```
```{r}
# update the function call to drop all existing columns
dogs <- dogs %>%
transmute(breed = breed, avg_height = (height_low_inches + height_high_inches)/2,
avg_weight = (weight_low_lbs + weight_high_lbs)/2,
rank_change_13_to_16 = rank_2016 - rank_2013)
head(dogs)
```
---
title: "Modifying Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```
```{r}
# inspect data frame
head(dogs)
```
```{r}
# update the function call to drop all existing columns
dogs <- dogs %>%
transmute(breed = breed, avg_height = (height_low_inches + height_high_inches)/2,
avg_weight = (weight_low_lbs + weight_high_lbs)/2,
rank_change_13_to_16 = rank_2016 - rank_2013)
head(dogs)
```
Codecademy Learn R Adding Multiple Columns 3/6
#Sample Solution
---
title: "Modifying Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```
```{r}
# inspect data frame
head(dogs)
```
```{r}
# add average height, average weight and rank change columns
dogs <- dogs %>%
mutate(avg_height = (height_low_inches + height_high_inches)/2, avg_weight = (weight_low_lbs + weight_high_lbs)/2, rank_change_13_to_16 = rank_2016 - rank_2013)
head(dogs)
---
title: "Modifying Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```
```{r}
# inspect data frame
head(dogs)
```
```{r}
# add average height, average weight and rank change columns
dogs <- dogs %>%
mutate(avg_height = (height_low_inches + height_high_inches)/2, avg_weight = (weight_low_lbs + weight_high_lbs)/2, rank_change_13_to_16 = rank_2016 - rank_2013)
head(dogs)
Codecademy Learn R Adding a Column 2/6
#Sample Solution
---
title: "Modifying Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```
```{r}
# inspect data frame
head(dogs)
```
```{r}
# add average height column
dogs <- dogs %>% mutate(avg_height = (height_low_inches + height_high_inches)/2)
head(dogs)
```
---
title: "Modifying Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```
```{r}
# inspect data frame
head(dogs)
```
```{r}
# add average height column
dogs <- dogs %>% mutate(avg_height = (height_low_inches + height_high_inches)/2)
head(dogs)
```
Codecademy Learn R Review 12/12
#Sample Solution
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# select columns
chosen_cols <- artists %>%
select(-country,-year_founded,-albums)
head(chosen_cols)
```
```{r}
# filter rows
popular_not_hip_hop <- chosen_cols %>%
filter(spotify_monthly_listeners > 20000000, genre != 'Hip Hop')
head(popular_not_hip_hop)
```
```{r}
# arrange rows
youtube_desc <- popular_not_hip_hop %>%
arrange(desc(youtube_subscribers))
head(youtube_desc)
```
```{r}
# select columns, filter and arrange rows
artists <- artists %>% select(-country,-year_founded,-albums) %>% filter(spotify_monthly_listeners > 20000000, genre != 'Hip Hop') %>% arrange(desc(youtube_subscribers))
head(artists)
```
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# select columns
chosen_cols <- artists %>%
select(-country,-year_founded,-albums)
head(chosen_cols)
```
```{r}
# filter rows
popular_not_hip_hop <- chosen_cols %>%
filter(spotify_monthly_listeners > 20000000, genre != 'Hip Hop')
head(popular_not_hip_hop)
```
```{r}
# arrange rows
youtube_desc <- popular_not_hip_hop %>%
arrange(desc(youtube_subscribers))
head(youtube_desc)
```
```{r}
# select columns, filter and arrange rows
artists <- artists %>% select(-country,-year_founded,-albums) %>% filter(spotify_monthly_listeners > 20000000, genre != 'Hip Hop') %>% arrange(desc(youtube_subscribers))
head(artists)
```
Codecademy Learn R Arranging Rows 11/12
#Sample Solution
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# arrange rows in ascending order
group_asc <- artists %>% arrange(group)
group_asc
```
```{r}
# arrange rows in descending order
youtube_desc <- artists %>% arrange(desc(youtube_subscribers))
youtube_desc
```
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# arrange rows in ascending order
group_asc <- artists %>% arrange(group)
group_asc
```
```{r}
# arrange rows in descending order
youtube_desc <- artists %>% arrange(desc(youtube_subscribers))
youtube_desc
```
Codecademy Learn R Filtering Rows with Logic II 10/12
#Sample Solution
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# filter rows with or
korea_or_before_2000 <- artists %>% filter(country == 'South Korea' | year_founded < 2000)
korea_or_before_2000
```
```{r}
# filter rows with not !
not_rock_groups <- artists %>% filter(!(genre == 'Rock'))
not_rock_groups
```
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# filter rows with or
korea_or_before_2000 <- artists %>% filter(country == 'South Korea' | year_founded < 2000)
korea_or_before_2000
```
```{r}
# filter rows with not !
not_rock_groups <- artists %>% filter(!(genre == 'Rock'))
not_rock_groups
```
Codecademy Learn R Filtering Rows with Logic I 9/12
#Sample Solution
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# filter rows one condition
rock_groups <- artists %>% filter(genre == 'Rock')
rock_groups
```
```{r}
# filter rows multiple conditions
popular_rock_groups <- artists %>% filter(genre == 'Rock', spotify_monthly_listeners > 20000000)
popular_rock_groups
```
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# filter rows one condition
rock_groups <- artists %>% filter(genre == 'Rock')
rock_groups
```
```{r}
# filter rows multiple conditions
popular_rock_groups <- artists %>% filter(genre == 'Rock', spotify_monthly_listeners > 20000000)
popular_rock_groups
```
Codecademy Learn R Excluding Columns 8/12
#Sample Solution
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# select all columns except one
no_albums <- artists %>% select(-albums)
no_albums
```
```{r}
# select all columns except a set
df_cols_removed <- artists %>% select(-genre,-spotify_monthly_listeners,-year_founded)
df_cols_removed
```
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# select all columns except one
no_albums <- artists %>% select(-albums)
no_albums
```
```{r}
# select all columns except a set
df_cols_removed <- artists %>% select(-genre,-spotify_monthly_listeners,-year_founded)
df_cols_removed
```
Codecademy Learn R Selecting Columns 7/12
#Sample Solution
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# select one column
artist_groups <- artists %>% select(group)
artist_groups
```
```{r}
# select multiple columns
group_info <- artists %>% select(group, spotify_monthly_listeners, year_founded)
group_info
```
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# select one column
artist_groups <- artists %>% select(group)
artist_groups
```
```{r}
# select multiple columns
group_info <- artists %>% select(group, spotify_monthly_listeners, year_founded)
group_info
```
Codecademy Learn R Piping 6/12
#Sample Solution
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# inspect data frame with pipe
artists %>% head()
```
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# inspect data frame with pipe
artists %>% head()
```
Codecademy Learn R Inspecting Data Frames 5/12
#Sample Solution
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# inspect data frame
artists
head(artists)
summary(artists)
```
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r message=FALSE}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# inspect data frame
artists
head(artists)
summary(artists)
```
Codecademy Learn R Loading and Saving CSVs 4/12
#Sample Solution
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r}
# load data frame
artists <- read_csv('artists.csv')
artists
```
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r}
# load data frame
artists <- read_csv('artists.csv')
artists
```
Codecademy Learn R CSVs 3/12
#Sample Solution
name,cake_flavor,frosting_flavor,topping
Red Velvet Cake,chocolate,cream cheese,strawberries
Birthday Cake,vanilla,vanilla,rainbow sprinkles
Carrot Cake,carrot,cream cheese,almonds
name,cake_flavor,frosting_flavor,topping
Red Velvet Cake,chocolate,cream cheese,strawberries
Birthday Cake,vanilla,vanilla,rainbow sprinkles
Carrot Cake,carrot,cream cheese,almonds
Codecademy Learn R What is a Data Frame? 2/12
#Sample Solution
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r}
# load data frame
songs <- read_csv('songs.csv')
```
```{r}
songs
```
---
title: "Introduction to Data Frames in R"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r}
# load data frame
songs <- read_csv('songs.csv')
```
```{r}
songs
```
Codecademy Learn R Introduction To Data Framed In R 1/12
#Sample Solution
---
title: "Introduction to Data Frames"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# inspect data frame
artists
head(artists)
summary(artists)
```
```{r}
# select columns, filter and arrange rows of artists
artists_manipulated <- artists %>%
select(-country,-year_founded,-albums) %>%
filter(spotify_monthly_listeners > 20000000, genre != 'Hip Hop') %>%
arrange(desc(youtube_subscribers))
artists_manipulated
```
---
title: "Introduction to Data Frames"
output: html_notebook
---
```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```
```{r}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# inspect data frame
artists
head(artists)
summary(artists)
```
```{r}
# select columns, filter and arrange rows of artists
artists_manipulated <- artists %>%
select(-country,-year_founded,-albums) %>%
filter(spotify_monthly_listeners > 20000000, genre != 'Hip Hop') %>%
arrange(desc(youtube_subscribers))
artists_manipulated
```
Codecademy Learn R Importing Packages 11/12
#Sample Solution
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
# load libraries
library(dplyr)
library(readr)
```
```{r}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# inspect data frame
artists
head(artists)
summary(artists)
```
```{r}
artists %>%
select(-country,-year_founded,-albums) %>%
filter(spotify_monthly_listeners > 20000000, genre != 'Hip Hop') %>%
arrange(desc(youtube_subscribers))
```
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
# load libraries
library(dplyr)
library(readr)
```
```{r}
# load data frame
artists <- read_csv('artists.csv')
```
```{r}
# inspect data frame
artists
head(artists)
summary(artists)
```
```{r}
artists %>%
select(-country,-year_founded,-albums) %>%
filter(spotify_monthly_listeners > 20000000, genre != 'Hip Hop') %>%
arrange(desc(youtube_subscribers))
```
Codecademy Learn R Calling a Function 10/12
#Sample Solution
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
data <- c(120,22,22,31,15,120)
unique_vals <- unique(data)
print(unique_vals)
solution <- sqrt(49)
print(solution)
round_down <- floor(3.14)
round_up <- ceiling(3.14)
print(round_down)
print(round_up)
```
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
data <- c(120,22,22,31,15,120)
unique_vals <- unique(data)
print(unique_vals)
solution <- sqrt(49)
print(solution)
round_down <- floor(3.14)
round_up <- ceiling(3.14)
print(round_down)
print(round_up)
```
Codecademy Learn R Logical Operators 9/12
#Sample Solution
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
message <- 'Should I pack an umbrella?'
weather <- 'cloudy'
high_chance_of_rain <- TRUE
if(weather == 'cloudy' & high_chance_of_rain){
message <- "Pack umbrella!"
} else {
message <- "No need for umbrella!"
}
print(message) #Pack umbrella!
```
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
message <- 'Should I pack an umbrella?'
weather <- 'cloudy'
high_chance_of_rain <- TRUE
if(weather == 'cloudy' & high_chance_of_rain){
message <- "Pack umbrella!"
} else {
message <- "No need for umbrella!"
}
print(message) #Pack umbrella!
```
Codecademy Learn R Comparison Operators 8/12
#Sample Solution
Comparison Operators
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
56 >= 129 #FALSE
56 != 129 #TRUE
```
Comparison Operators
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
56 >= 129 #FALSE
56 != 129 #TRUE
```
Codecademy Learn R Conditionals 7/12
#Sample Solution
```{r}
message <- "I change based on a condition."
if(TRUE){
message <- 'I execute this when true!'
} else{
message <- 'I execute this when false!'
}
print(message)
```
```{r}
message <- "I change based on a condition."
if(TRUE){
message <- 'I execute this when true!'
} else{
message <- 'I execute this when false!'
}
print(message)
```
Codecademy Learn R Vectors 6/12
#Sample Solution
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
phone <- c(987, 654, 3210)
```
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
phone <- c(987, 654, 3210)
```
Codecademy Learn R Variables 5/12
#Sample Solution
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
name <- 'Nathan'
age <- 65
```
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
name <- 'Nathan'
age <- 65
```
Codecademy Learn R Data Types 4/12
#Sample Solution
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
print('Nathan')
print(65)
print('65')
```
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
print('Nathan')
print(65)
print('65')
```
Codecademy Learn R Comments 3/12
#Sample Solution
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
#This will compute the volume of a cube with one side length equal to 3. This will result in 27
3 * 3 * 3
```
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
#This will compute the volume of a cube with one side length equal to 3. This will result in 27
3 * 3 * 3
```
Codecademy Learn R Calculations 2/12
---
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
25 * 4 + 9 / 3
```
title: "Introduction to R Syntax"
output: html_notebook
---
```{r}
25 * 4 + 9 / 3
```
Codecademy Main() 8/8
// Sample Solution
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Forest.ForestsCreated);
Forest f = new Forest("Forest F");
Forest g = new Forest("Forest G");
Console.WriteLine(Forest.ForestsCreated);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Forest.ForestsCreated);
Forest f = new Forest("Forest F");
Forest g = new Forest("Forest G");
Console.WriteLine(Forest.ForestsCreated);
}
}
}
Codecademy Common Static Errors 6/8
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
static Forest()
{
treeFacts = "Forests provide a diversity of ecosystem services including:\r\n aiding in regulating climate.\r\n purifying water.\r\n mitigating natural hazards such as floods.\n";
ForestsCreated = 0;
}
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Grow();
Console.WriteLine(Forest.TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
static Forest()
{
treeFacts = "Forests provide a diversity of ecosystem services including:\r\n aiding in regulating climate.\r\n purifying water.\r\n mitigating natural hazards such as floods.\n";
ForestsCreated = 0;
}
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Grow();
Console.WriteLine(Forest.TreeFacts);
}
}
}
Codecademy Static Classes 5/8
// Sample Solution
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Math.PI);
Console.WriteLine(Math.Abs(-32));
}
}
}
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Math.PI);
Console.WriteLine(Math.Abs(-32));
}
}
}
Codecademy Static Constructors 4/8
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
static Forest()
{
treeFacts = "Forests provide a diversity of ecosystem services including:\r\n aiding in regulating climate.\r\n purifying water.\r\n mitigating natural hazards such as floods.\n";
ForestsCreated = 0;
}
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Forest.PrintTreeFacts();
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
static Forest()
{
treeFacts = "Forests provide a diversity of ecosystem services including:\r\n aiding in regulating climate.\r\n purifying water.\r\n mitigating natural hazards such as floods.\n";
ForestsCreated = 0;
}
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Forest.PrintTreeFacts();
}
}
}
Codecademy Static Methods 3/8
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
Codecademy Static Fields and Properties 2/8
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
Codecademy Review 12/12
// Sample Solution
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Amazon");
Console.WriteLine(f.Trees);
f.Grow();
Console.WriteLine(f.Trees);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Amazon");
Console.WriteLine(f.Trees);
f.Grow();
Console.WriteLine(f.Trees);
}
}
}
Codecademy Overloading Constructors 11/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
}
//Second constructor
public Forest(string name) : this(name, "Unknown")
{
Console.WriteLine("Biome property not specified. Value defaulted to 'Unknown'.");
}
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Trees = 0;
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
Forest g = new Forest("Rendlesham");
Console.WriteLine(g.Biome);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
}
//Second constructor
public Forest(string name) : this(name, "Unknown")
{
Console.WriteLine("Biome property not specified. Value defaulted to 'Unknown'.");
}
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Trees = 0;
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
Forest g = new Forest("Rendlesham");
Console.WriteLine(g.Biome);
}
}
}
Codecademy Constructors 10/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
}
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
}
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
Codecademy Constructors 9/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public Forest(string name, string biome)
{
Name = name;
Biome = biome;
Age = 0;
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Trees = 0;
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public Forest(string name, string biome)
{
Name = name;
Biome = biome;
Age = 0;
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Trees = 0;
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
}
}
}
Codecademy Methods 8/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees = Trees + 30;
Age = Age + 1;
return Trees;
}
public int Burn()
{
Trees = Trees - 20;
Age = Age + 1;
return Trees;
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees = Trees + 30;
Age = Age + 1;
return Trees;
}
public int Burn()
{
Trees = Trees - 20;
Age = Age + 1;
return Trees;
}
}
}
Codecademy Public vs. Private 6/12
// Sample Solution
using System;
///////////////////////////////////////////////////
// Forest.cs code
namespace BasicClasses
{
class Forest
{
public int age;
public string Name
{ get; set; }
public int Trees
{ get; set; }
private string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
f.Name = "Congo";
f.Trees = 0;
f.age = 0;
f.Biome = "Desert";
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
}
}
}
using System;
///////////////////////////////////////////////////
// Forest.cs code
namespace BasicClasses
{
class Forest
{
public int age;
public string Name
{ get; set; }
public int Trees
{ get; set; }
private string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
f.Name = "Congo";
f.Trees = 0;
f.age = 0;
f.Biome = "Desert";
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
}
}
}
Codecademy Automatic Properties 5/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
public string biome;
public string Name { get; set; }
public int Trees { get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
public string biome;
public string Name { get; set; }
public int Trees { get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
Codecademy Properties 4/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public string name;
public string Name
{
get { return name; }
set { name = value; }
}
public int trees;
public int Trees
{
get { return trees; }
set { trees = value; }
}
public int age;
public string biome;
public string Biome
{
get { return biome; }
set {
if(value == "Tropical" || value == "Temperate" || value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
f.Name = "Congo";
f.Trees = 0;
f.age = 0;
f.biome = "Tropical";
Console.WriteLine(f.Name);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public string name;
public string Name
{
get { return name; }
set { name = value; }
}
public int trees;
public int Trees
{
get { return trees; }
set { trees = value; }
}
public int age;
public string biome;
public string Biome
{
get { return biome; }
set {
if(value == "Tropical" || value == "Temperate" || value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
f.Name = "Congo";
f.Trees = 0;
f.age = 0;
f.biome = "Tropical";
Console.WriteLine(f.Name);
}
}
}
Subscribe to:
Posts (Atom)
This is an example of scrolling text using Javascript.
Popular Posts
-
var my_canvas=document.getElementById('canvas'); var context=my_canvas.getContext('2d');
-
This is caused by the entrance of water into the air sacs which makes the lungs doughy, readily pits on pressure, exuding water and froth
-
Question: What current is required for full scale deflection of a galvanometer having a current sensitivity of 50 micro-amperes per scale di...
-
#sample solution print "What's your first name?" first_name = gets.chomp.capitalize! print "What's your last na...
-
//Sample Solution const gameState = {} function preload() { this.load.image('codey', 'https://s3.amazonaws.com/codecademy-...
-
#Sample Solution --- title: "Data Cleaning in R" output: html_notebook --- ```{r message=FALSE, warning=FALSE} # load libra...
-
Solution: SELECT first_name, age, FROM table_name;
-
# Update data types year_1_str = str(year_1) revenue_1_str = str(revenue_1) # Create a complete sentence combining only the string d...
-
#sample solution secret_identities = { "The Batman" => "Bruce Wayne", "Superman" => "Clark Ke...
-
Answer: This is the type of injury when a blow to the forehead causes a contusion of the eyeball due to the fracture of the bone at the r...