data.frame有比预期更多的列

时间:2017-07-17 16:34:21

标签: r dataframe

我正在通过NY Times API下载数据,并且在尝试对多个数据帧进行行绑定时遇到了一个奇怪的错误。

我从data.frame获得两行和两列,如下所示:

a = head(nydata[,c(5,9)],2)

这是dput()结果:

> dput(a)
structure(list(print_page = c(NA, "4"), headline = structure(list(
    main = c("Donald Trump’s Letter", "A Rabbi’s Enduring Sermon on Living Your Last Five Minutes"
    ), content_kicker = c(NA, "On Religion"), kicker = c(NA, 
    "On Religion"), print_headline = c(NA, "The Enduring Lessons of ‘Five Minutes to Live’"
    )), .Names = c("main", "content_kicker", "kicker", "print_headline"
), row.names = 1:2, class = "data.frame")), .Names = c("print_page", 
"headline"), row.names = 1:2, class = "data.frame")

属性(a)表明数据框确实有两列。

> attributes(a)
$names
[1] "print_page" "headline"  

$row.names
[1] 1 2

$class
[1] "data.frame"

但总结显示不然!

> summary(a)
  print_page          headline.main     headline.content_kicker   headline.kicker    headline.print_headline
 Length:2           Length:2            Length:2            Length:2            Length:2                    
 Class :character   Class :character    Class :character    Class :character    Class :character            
 Mode  :character   Mode  :character    Mode  :character    Mode  :character    Mode  :character    

我认为,当我解决这个问题时,我将能够对数据帧进行rowbind。这对任何人来说都很熟悉,或者是否有人知道是什么导致了这种不一致?

谢谢!

0 个答案:

没有答案