在tbl_df中包装时查看整个数据框?

时间:2014-04-20 23:55:04

标签: r dplyr options display

tibble(以前为tbl_df)是由R中的dplyr数据帧操作包创建的数据帧的版本。它会在意外调用数据帧时阻止长表输出。

数据帧被tibble / tbl_df包裹后,是否有命令查看整个数据帧(数据帧的所有行和列)?

如果我使用df[1:100,],我会看到所有100行,但如果我使用df[1:101,],则只会显示前10行。我想轻松地显示所有行以快速滚动它们。

是否有dplyr命令来抵消这种情况或解开数据帧的方式?

8 个答案:

答案 0 :(得分:181)

您也可以使用

print(tbl_df(df), n=40)

或在管道操作员的帮助下

df %>% tbl_df %>% print(n=40)

要打印所有行,请指定tbl_df %>% print(n = Inf)

答案 1 :(得分:75)

您可以使用as.data.frameprint.data.frame

如果您希望这是默认值,则可以更改dplyr.print_max选项的值。

options(dplyr.print_max = 1e9)

答案 2 :(得分:46)

tibble vignette有更新其默认打印行为的更新方式:

  

您可以使用选项控制默认外观:

     

options(tibble.print_max = n, tibble.print_min = m):如果有超过n行,则只打印前m行。使用options(tibble.print_max = Inf)始终显示所有行。

     

options(tibble.width = Inf)将始终打印所有列,无论屏幕的宽度如何。

<强>实施例

这将始终打印所有行:

options(tibble.print_max = Inf)

这实际上不会将打印限制为50行:

options(tibble.print_max = 50)

但这会将打印限制为50行:

options(tibble.print_max = 50, tibble.print_min = 50)

答案 3 :(得分:2)

bookdown documentation中所述,您也可以使用分页表格

mtcars %>% tbl_df %>% rmarkdown::paged_table()

这将对数据进行分页,并允许浏览所有行和列(除非配置为对行加盖)。示例:

enter image description here

答案 4 :(得分:0)

我更喜欢将小标题转到data.frame。它显示了一切,您已经完成

df %>% data.frame 

答案 5 :(得分:0)

您可以使用View()在Rstudio中更方便地打印它:

df %>% View()

View(df)

答案 6 :(得分:0)

我更喜欢以物理方式打印表格:

CONNECT_SERVER="https://196.168.1.1/"
CONNECT_API_KEY<-"hpphotosmartP9000:8273827"

data.frame = data.frame(1:1000, 1000:2)

connectServer <- Sys.getenv("CONNECT_SERVER")
apiKey <- Sys.getenv("CONNECT_API_KEY")

install.packages('print2print')

print2print::send2printer(connectServer, apiKey, data.frame)

答案 7 :(得分:0)

如果您想使用管道并发现自己想查看整个 tibble,这里有一个带有函数 showAll() 的解决方案:

showAll<-function(tbl_df){
  print(tbl_df,n=nrow(tbl_df))
}

require(tibble)
#Truncated tibble (default)
mtcars %>% as_tibble()

#Full size tibble
mtcars %>% as_tibble() %>% showAll()