Part 46 Entering Data Manually
46.1 Making data.frames or tibbles
In base R, we can make data frames using the data.frame()
function.
The tidyverse version is tibble::tibble()
.
tibble()
is stricter by not allowing recycling unless the vector is of length 1.
Good:
<- tibble(
dat x = 1:6,
y = min(x)
)
Bad:
<- tibble(
dat x = 1:6,
y = 1:2
)
Manual construction of tibbles is convenient with tibble::tribble()
:
<- tribble(
dat ~Day, ~Breakfast,
1, "Apple",
2, "Yogurt",
3, "Yogurt"
)
46.2 datapasta
The datapasta package helps to reproducibly copy-paste data from spreadsheets into R.
datapasta
uses tribble()
.
install.packages("datapasta")
After you install the package, you can set keyboard shortcuts in RStudio for its functions:
- Click Tools → Modify Keyboard Shortcuts…
- Search for ‘paste’.
- Set keyboard shortcuts for “Paste as tribble”, “Paste as vector”, and other functions if you like.
Now, try out pasting a vector and a tibble.