Introduction to R and Rstudio

Session - import data {datapasta}

Zoë Turner

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}.

As an addin it only needs to be loaded and run once:

library(datapasta)

Add ins

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, 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)
  4. Run the code
10:00

A data frame in code

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