Reputation: 3269
I just attempted to read into R a Pandas dataframe stored to disk with Feather. After reading the dataframe in, I checked the type of the object and instead of seeing 'data.frame'
as the result, I see 'tbl_df' 'tbl' 'data.frame'
. Any idea what is going on here?
Relevant code is simply:
contact_records_df <- read_feather('contact_records.feather')
class(contact_records_df)
Upvotes: 1
Views: 847
Reputation: 262
It's just brought it in as a tibble, which is more or less an 'enhanced' dataframe from the tidyverse world. You can see the docs here
You can use them interchangably with dataframes. I have noticed once in awhile, especially with spatial functions, that tibbles cause something to die so you sometimes have to convert them back to a dataframe.
library(tibble)
x1 <- c(1, 2, 3, 4)
x2 <- c("one", "two", "three", "four")
example_df <- data.frame(x1,x2)
example_tibble <- tibble(x1,x2)
If you check out the two of them using str
, you'll see they are basically the same except tibbles won't auto convert strings to factors (among other things).
> str(example_df)
'data.frame': 4 obs. of 2 variables:
$ x1: num 1 2 3 4
$ x2: Factor w/ 4 levels "four","one","three",..: 2 4 3 1
> str(example_tibble)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 4 obs. of 2 variables:
$ x1: num 1 2 3 4
$ x2: chr "one" "two" "three" "four"
Also, it's still a dataframe but it has some more specific classes
> is.data.frame(example_tibble)
[1] TRUE
Upvotes: 2