Home > Blockchain >  Why is the result of glimpse() a tibble for some but not all data?
Why is the result of glimpse() a tibble for some but not all data?

Time:09-16

So I'm running some code on a dataset that is 9992 rows and 10 columns. Specifically, I'm checking if the dataset's glimpse is a tibble, i.e., data %>% glimpse() %>% is_tibble(). It is outputting TRUE. But on other datasets, like the cars dataset, I'm getting FALSE. Why might this be the case?

I ran data %>% glimpse() %>% is_tibble() and cars %>% glimpse() %>% is_tibble()

CodePudding user response:

glimpse just prints the data in a transposed way and it does nothing on the data. The is_tibble will return TRUE only if the underlying data is tibble. Here, cars is not

> class(cars)
[1] "data.frame"

If we convert to tibble, it will show TRUE for is_tibble

> cars %>% 
  as_tibble %>% 
  glimpse() %>% 
  is_tibble()
Rows: 50
Columns: 2
$ speed <dbl> 4, 4, 7, 7, 8, 9, 10, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 16, 16, 17, 17,…
$ dist  <dbl> 2, 10, 4, 22, 16, 10, 18, 26, 34, 17, 28, 14, 20, 24, 28, 26, 34, 34, 46, 26, 36, 60, 80, 20, 26, 54, 32, 40, 32,…
[1] TRUE
  • Related