-
Notifications
You must be signed in to change notification settings - Fork 4
/
session-datapasta.qmd
71 lines (53 loc) · 2.11 KB
/
session-datapasta.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
title: "Introduction to R and Rstudio"
subtitle: "Session - import data {datapasta}"
author: "Zoë Turner"
execute:
eval: true
---
```{r}
#| echo: false
#| label: "libs"
#| include: false
library(countdown)
```
## Text data
It can happen where someone emails a small table that you need in R.
There is a way to copy it to create a dataset directly in R using [{datapasta}](https://milesmcbain.github.io/datapasta/).
As an addin it only needs to be loaded and run once:
```{r}
library(datapasta)
```
## Add ins
<img src="img/session03/datapasta-dropdown.PNG" alt="Screenshot of the datapasta list in the drop down menu under Help."/>
## Have a go!
1. Using a small [csv file for number and percentage of NHS staff by ethnicity](https://www.ethnicity-facts-figures.service.gov.uk/culture-and-community/digital/internet-use/latest/downloads/by-ethnicity.csv), open the csv, highlight the data including the column names and copy (Ctrl+C)
2. In a script or Quarto R chunk, select the `Addins/Paste as tribble`
3. Add code to make this an object (hint: it needs a name and an assign operator)
3. Run the code
```{r}
#| echo: false
#| eval: true
countdown::countdown(minutes = 10,
color_border = "#005EB8",
color_text = "#005EB8",
color_running_text = "white",
color_running_background = "#005EB8",
color_finished_text = "#005EB8",
color_finished_background = "white",
margin = "0.9em",
font_size = "2em")
```
## A data frame in code
```{r}
by_ethnicity <- tibble::tribble(
~Ethnicity, ~`%`, ~Headcount, ~`%.working.age.population.(2011)`,
"Asian", 10, 118396, 7.2,
"Black", 6.1, 72321, 3.4,
"Chinese", 0.6, 6536, 0.9,
"Mixed", 1.7, 20607, 1.8,
"White", 79.2, 934544, 85.6,
"Other", 2.3, 27169, 1.1
)
```
## End session