Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

This repository contains _all_ programming exercises for the [_Programming Skills for Data Science_](https://programming-for-data-science.github.io/) book.

Solutions can be found in the `solution` branch.
Solutions can be found in the `solution` branch.

### "Cidade Deus" is a great film

Binary file added chapter-05-exercises/exercise-1/.RData
Binary file not shown.
2 changes: 2 additions & 0 deletions chapter-05-exercises/exercise-1/.Rhistory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
too_expensive = FALES
too_expensive = FALSE
18 changes: 11 additions & 7 deletions chapter-05-exercises/exercise-1/exercise.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# Exercise 1: practice with basic R syntax

# Create a variable `hometown` that stores the city in which you were born

hometown <- "Toledo"

# Assign your name to the variable `my_name`

my_name <- "Alejandro"

# Assign your height (in inches) to a variable `my_height`

my_height <- 1.74

# Create a variable `puppies` equal to the number of puppies you'd like to have

puppies <- 0

# Create a variable `puppy_price`, which is how much you think a puppy costs

puppy_price <- 20

# Create a variable `total_cost` that has the total cost of all of your puppies

total_cost <- 20

# Create a boolean variable `too_expensive`, set to TRUE if the cost is greater
# than $1,000

if total_cost > 1000:
too_expensive = TRUE
else
too_expensive = FALSE


# Create a variable `max_puppies`, which is the number of puppies you can
# afford for $1,000
Empty file.
Binary file added chapter-08-exercises/exercise-1/.RData
Binary file not shown.
80 changes: 80 additions & 0 deletions chapter-08-exercises/exercise-1/.Rhistory
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
meals
# Create a vector `my_breakfast` of everything you ate for breakfast
my_breakfast <- c("leche", "galletas")
# Create a vector `my_lunch` of everything you ate (or will eat) for lunch
my_lunch <- c("tomate", "lechuga", "coliflor")
# Create a list `meals` that has contains your breakfast and lunch
meals <- my_lunch + my_breakfast
# Create a list `meals` that has contains your breakfast and lunch
meals <- my_lunch, my_breakfast
# Create a list `meals` that has contains your breakfast and lunch
meals <- c(my_lunch, my_breakfast)
meals
# Add a "dinner" element to your `meals` list that has what you plan to eat
# for dinner
dinner <- c("hamburguesa", "patatas fritas")
meals <- c(meals, dinner)
meals
# Use dollar notation to extract your `dinner` element from your list
# and save it in a vector called 'dinner'
dinner2 <- meals[2]
dinner2
# Use dollar notation to extract your `dinner` element from your list
# and save it in a vector called 'dinner'
dinner2 <- meals[-1]
dinner2
# Use dollar notation to extract your `dinner` element from your list
# and save it in a vector called 'dinner'
dinner2 <- meals[length(meals)]
dinner2
meals
meals <- c(c(meals), c(dinner)
meals <- c(c(meals), c(dinner))
# Use dollar notation to extract your `dinner` element from your list
# and save it in a vector called 'dinner'
dinner2 <- meals[length(meals)]
dinner2
# Use double-bracket notation to extract your `lunch` element from your list
# and save it in your list as the element at index 5 (no reason beyond practice)
meals[1:4]
# Create a list that has the number of items you ate for each meal
# Hint: use the `lappy()` function to apply the `length()` function to each item
l <- list(breakfast : c("leche","cafe"),
dinner : c("hamburguesa", "patatas"))
# Create a list that has the number of items you ate for each meal
# Hint: use the `lappy()` function to apply the `length()` function to each item
l <- list(breakfast = c("leche","cafe"),
dinner = c("hamburguesa", "patatas"))
l
lapply(l, length())
l[1]
lapply(l[1], length())
length(l[1])
length(l[2])
lapply(l, length)
lapply(l, length)
return "pizza"
# Write a function `add_pizza` that adds pizza to a given meal vector, and
# returns the pizza-fied vector
add_pizza <- function(){
return "pizza"
}
return p
return p;
return
return p
return p
return("pizza")
# Write a function `add_pizza` that adds pizza to a given meal vector, and
# returns the pizza-fied vector
add_pizza <- function(){
return("pizza")
}
lapply(l, add_pizza)
# Write a function `add_pizza` that adds pizza to a given meal vector, and
# returns the pizza-fied vector
add_pizza <- function(ventrada, vsalida){
vsalida <- c(ventrada, "pizza")
return(vsalida)
}
lapply(l, add_pizza)
26 changes: 18 additions & 8 deletions chapter-08-exercises/exercise-1/exercise.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
# Exercise 1: creating and accessing lists

# Create a vector `my_breakfast` of everything you ate for breakfast

my_breakfast <- c("leche", "galletas")

# Create a vector `my_lunch` of everything you ate (or will eat) for lunch

my_lunch <- c("tomate", "lechuga", "coliflor")

# Create a list `meals` that has contains your breakfast and lunch

meals <- c(my_lunch, my_breakfast)
meals

# Add a "dinner" element to your `meals` list that has what you plan to eat
# for dinner

dinner <- c("hamburguesa", "patatas fritas")
meals <- c(meals, dinner)
meals

# Use dollar notation to extract your `dinner` element from your list
# and save it in a vector called 'dinner'

dinner2 <- meals[length(meals)]
dinner2

# Use double-bracket notation to extract your `lunch` element from your list
# and save it in your list as the element at index 5 (no reason beyond practice)

meals[1:4]

# Use single-bracket notation to extract your breakfast and lunch from your list
# and save them to a list called `early_meals`
Expand All @@ -30,11 +34,17 @@

# Create a list that has the number of items you ate for each meal
# Hint: use the `lappy()` function to apply the `length()` function to each item

l <- list(breakfast = c("leche","cafe"),
dinner = c("hamburguesa", "patatas"))
lapply(l, length)

# Write a function `add_pizza` that adds pizza to a given meal vector, and
# returns the pizza-fied vector

add_pizza <- function(ventrada, vsalida){
vsalida <- c(ventrada, "pizza")
return(vsalida)
}
lapply(l, add_pizza)

# Create a vector `better_meals` that is all your meals, but with pizza!

Binary file added chapter-17-exercises/exercise-1/.RData
Binary file not shown.
Loading