Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Resumen

Summary DSCI Tutorial 2 - tutorial_reading_solution (2022)

Puntuación
-
Vendido
-
Páginas
13
Subido en
11-04-2022
Escrito en
2021/2022

Solutions to dsci 100 tutorial_reading

Institución
Grado

Vista previa del contenido

Tutorial 2: Introduction to Reading Data
Lecture and Tutorial Learning Goals:

After completing this week's lecture and tutorial work, you will be able to:

define the following:
absolute file path
relative file path
url
read data into R using a relative path and a url
compare and contrast the following functions:
read_csv
read_tsv
read_csv2
read_delim
read_excel
match the following tidyverse read_* function arguments to their descriptions:
file
delim
col_names
skip
choose the appropriate tidyverse read_* function and function arguments to load a given plain text tabular data set into R
use readxl library's read_excel function and arguments to load a sheet from an excel file into R
connect to a database using the DBI library's dbConnect function
list the tables in a database using the DBI library's dbListTables function
create a reference to a database table that is queriable using the tbl from the dbplyr library
retrieve data from a database query and bring it into R using the collect function from the dbplyr library
use write_csv to save a data frame to a csv file
optional: scrape data from the web
read/scrape data from an internet URL using the rvest html_nodes and html_text functions
compare downloading tabular data from a plain text file (e.g. *.csv ) from the web versus scraping data from a .html file

Any place you see ... , you must fill in the function, variable, or data to complete the code. Replace fail() with your completed code and run the
cell!


In [ ]:

### Run this cell before continuing.
library(tidyverse)
library(repr)
library(rvest)
library(stringr)
options(repr.matrix.max.rows = 6)
source("tests.R")
source("cleanup.R")



1. Happiness Report
As you might remember from worksheet_02 , we practised loading data from the Sustainable Development Solutions Network's World Happiness
Report (http://worldhappiness.report/). That data was the output of their analysis that calculated each country's happiness score and how much each
variable contributed to it. In this tutorial, we are going to look at the data at an earlier stage of the study - the aggregated/averaged values (per country and
year) for many different social and health aspects that the researchers anticipated might contribute to happiness (Table2.1 from this Excel spreadsheet
(https://s3.amazonaws.com/happiness-report/2018/WHR2018Chapter2OnlineData.xls)).

The goal for today is to produce a plot of 2017's positive affect scores against healthy life expectancy at birth, with healthy life expectancy at birth on the x-
axis and positive affect on the y-axis. For this study, positive affect was defined as the average of three positive affect measures: happiness, laughter and
enjoyment. We would also like to convert the positive affect score from a scale of 0 - 1 to a scale from 0 - 10.

1. use filter to subset the rows where the year is equal to 2017
2. use mutate to convert the "Positive affect" score from a scale of 0 - 1 to a scale from 0 - 10
3. use select to choose the "Healthy life expectancy at birth" column and the scaled "Positive affect" column
4. use ggplot to create our plot of "Healthy life expectancy at birth" (x - axis) and scaled "Positive affect" (y - axis)

Tips for success: Try going through all of the steps on your own, but don't forget to discuss with others (classmates, TAs, or an instructor) if you get
stuck. If something is wrong and you can't spot the issue, be sure to read the error message carefully. Since there are a lot of steps involved in working
with data and modifying it, feel free to look back at worksheet_02 .

, Question 1.1 Multiple Choice:
{points: 1}

What is the maximum value for the "Positive affect" score (in the original data file that you read into R)?

A. 100

B. 10

C. 1

D. 0.1

E. 5

Assign your answer to an object called answer1.1 . Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. "F" ).


In [ ]:

# Replace the fail() with your answer.

### BEGIN SOLUTION
answer1.1 <- "C"
### END SOLUTION


In [ ]:

test_1.1()


Question 1.2 Multiple Choice:
{points: 1}

Which column's values will be used to filter the data?

A. countries

B. generosity

C. positive affect

D. year

Assign your answer to an object called answer1.2 . Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. "F" ).


In [ ]:

# Replace the fail() with your answer.

### BEGIN SOLUTION
answer1.2 <- "D"
### END SOLUTION


In [ ]:

test_1.2()


Question 1.3.0
{points: 1}

Use the appropriate read_* function to read in the WHR2018Chapter2OnlineData (look in the tutorial_02 directory to ensure you use the
correct relative path to read it in).

_Assign the data frame to an object called happy_df_csv ._


In [ ]:

### BEGIN SOLUTION
happy_df_csv <- read_csv(file = "data/WHR2018Chapter2OnlineData.csv")
### END SOLUTION
happy_df_csv


In [ ]:

test_1.3.0()

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

Subido en
11 de abril de 2022
Número de páginas
13
Escrito en
2021/2022
Tipo
RESUMEN

Temas

$7.99
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
travissmith1 UBC
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
97
Miembro desde
4 año
Número de seguidores
61
Documentos
36
Última venta
5 meses hace

3.6

16 reseñas

5
6
4
6
3
0
2
0
1
4

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes