Error in library(tidyverse): there is no package called 'tidyverse'
Tibbles and readr
A tibble
is the modern tidyverse
version of a data.frame
. A tibble
is a data.frame
, and so can be used in the same way. But it comes with more powerful features and removes inconsistent and confusing behaviour.
In the same way, readr
provides modern tidyverse
replacements for R’s standard reading functions. readr
provides read_csv
, which is a better way of reading csv files than R’s standard read.csv
.
Let’s now use the tidyverse
to read_csv
the dataset Anatomical Data from Domestic Cats into a tibble
. The first thing you will notice is that the tidyverse
has printed out some useful information.
# Did you load tidyverse? library(tidyverse)
<- read_csv("https://raw.githubusercontent.com/Bristol-Training/intermediate-r/refs/heads/main/data/cats.csv") cats
Error in read_csv("https://raw.githubusercontent.com/Bristol-Training/intermediate-r/refs/heads/main/data/cats.csv"): could not find function "read_csv"
This is telling you that read_csv
found three columns; Sex
, which is treated as a columns of strings (characters), and BodyWeight
and HeartWeight
, which are both treated as columns of floating point numbers (doubles).
Next, if you type cats
and press return you will see
cats
Error: object 'cats' not found
that the tibble
summarises itself to the screen. This makes it much easier to quickly look at some data without it overflowing your console.
As a tibble
is a data.frame
, you can use the same methods of accessing data, e.g.
$BodyWeight cats
Error: object 'cats' not found
1,] cats[
Error: object 'cats' not found