https://github.com/maurolepore/loaddata
Load external data from a .csv file into a data frame (5' training for The Carpentries)
https://github.com/maurolepore/loaddata
carpentries carpentry instructors r rmarkdown training
Last synced: 12 months ago
JSON representation
Load external data from a .csv file into a data frame (5' training for The Carpentries)
- Host: GitHub
- URL: https://github.com/maurolepore/loaddata
- Owner: maurolepore
- Created: 2018-04-02T20:54:03.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2021-10-30T02:47:03.000Z (over 4 years ago)
- Last Synced: 2025-02-09T08:41:21.902Z (over 1 year ago)
- Topics: carpentries, carpentry, instructors, r, rmarkdown, training
- Homepage: http://bit.ly/carpentry-loaddata
- Size: 325 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
title: "Load external data from a .csv file into a data frame"
output:
github_document:
toc: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
comment = "#>",
collapse = TRUE
)
```
---
## See https://bit.ly/carpentry-slides
## Try by intuition
Document what you did.
```{r}
# Some code goes here
```
# Back to the lesson
> To download the data into the data/ subdirectory, run the following:
WARNING: This will fail. Why? (Run and read the error message)
Hint:
* Look in the Files tab. What's missing?
* What are the first two arguments of `download.file()`?
* Find out with the help of autocompletion (press TAB) or with `?`
```{r download-problem, error=TRUE}
# MISTERY-FUNCTION-GOES-HERE("data")
download.file(
"https://ndownloader.figshare.com/files/2292169",
"data/portal_data_joined.csv"
)
```
```{r download-solution, echo=FALSE}
# MISTERY-FUNCTION-GOES-HERE("data")
# TODO REMOVE
dir.create("data")
download.file(
"https://ndownloader.figshare.com/files/2292169",
"data/portal_data_joined.csv"
)
```
> You are now ready to load the data:
```{r}
surveys <- read.csv("data/portal_data_joined.csv")
```
> Print the variable's value: `surveys`
```{r, eval=FALSE}
# WARNING: In the console, this prints looooong output
surveys
```
> Let's check the top (the first 6 lines) of this data frame using the function `head()`:
```{r}
head(surveys)
```
# Thank you
* https://bit.ly/carpentry-slides
* https://bit.ly/mauro_lepore