2017-04-25 53 views
0

我刚刚尝试读入用羽毛存储到磁盘的R熊猫数据帧。在读入数据帧后,我检查了对象的类型,结果看到'data.frame',而我看到了'tbl_df' 'tbl' 'data.frame'。任何想法发生了什么?将用羽毛存储的熊猫数据帧读入R

相关的代码很简单: contact_records_df <- read_feather('contact_records.feather') class(contact_records_df)

+0

包装纸用'data.frame了'read_feather'调用(。)'似乎解决这个问题,但目前还不清楚对我来说为什么甚至是必要的。 – Chris

回答

1

它只是把它作为一个tibble,这是或多或少的“增强”从tidyverse世界数据帧。您可以看到文档here

您可以与数据框交换使用它们。我曾经注意到一段时间,特别是空间函数,蹒跚造成的东西死了,所以有时你必须将它们转换回数据帧。

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) 

如果你看看他们两个人使用str,你会看到他们基本上除了tibbles同样不会自动将字符串转换为因素(除其他事项外)。

> 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" 

此外,它仍然是一个数据帧,但是它有一些更具体的类

> is.data.frame(example_tibble) 
[1] TRUE