37

当我在本地数据框中有一列时,有时我会收到Variables not shown诸如这个(荒谬的)示例之类的消息,它只需要足够的列。

library(dplyr)
library(ggplot2) # for movies

movies %.% 
 group_by(year) %.% 
 summarise(Length = mean(length), Title = max(title), 
  Dramaz = sum(Drama), Actionz = sum(Action), 
  Action = sum(Action), Comedyz = sum(Comedy)) %.% 
 mutate(Year1 = year + 1)

   year    Length                       Title Dramaz Actionz Action Comedyz
1  1898  1.000000 Pack Train at Chilkoot Pass      1       0      0       2
2  1894  1.000000           Sioux Ghost Dance      0       0      0       0
3  1902  3.555556     Voyage dans la lune, Le      1       0      0       2
4  1893  1.000000            Blacksmith Scene      0       0      0       0
5  1912 24.382353            Unseen Enemy, An     22       0      0       4
6  1922 74.192308      Trapped by the Mormons     20       0      0      16
7  1895  1.000000                 Photographe      0       0      0       0
8  1909  9.266667              What Drink Did     14       0      0       7
9  1900  1.437500      Uncle Josh's Nightmare      2       0      0       5
10 1919 53.461538     When the Clouds Roll by     17       2      2      29
..  ...       ...                         ...    ...     ...    ...     ...
Variables not shown: Year1 (dbl)

我想看看Year1!我如何查看所有列,最好是默认情况下。

4

5 回答 5

52

(现在)有一种方法可以覆盖打印出来的列的宽度。如果你运行这个命令一切都会好起来的

options(dplyr.width = Inf)

我把它写在这里

于 2014-11-23T09:27:14.037 回答
31

您可能会喜欢glimpse

> movies %>%
+  group_by(year) %>%
+  summarise(Length = mean(length), Title = max(title),
+   Dramaz = sum(Drama), Actionz = sum(Action),
+   Action = sum(Action), Comedyz = sum(Comedy)) %>%
+  mutate(Year1 = year + 1) %>% glimpse()
Variables:
$ year    (int) 1893, 1894, 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902,...
$ Length  (dbl) 1.000000, 1.000000, 1.000000, 1.307692, 1.000000, 1.000000,...
$ Title   (chr) "Blacksmith Scene", "Sioux Ghost Dance", "Photographe", "Ve...
$ Dramaz  (int) 0, 0, 0, 1, 0, 1, 2, 2, 5, 1, 2, 3, 4, 5, 1, 8, 14, 14, 14,...
$ Actionz (int) 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 0, 3, 0, 0, 1, 0,...
$ Action  (int) 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 0, 3, 0, 0, 1, 0,...
$ Comedyz (int) 0, 0, 0, 1, 2, 2, 1, 5, 8, 2, 8, 10, 6, 2, 6, 8, 7, 2, 2, 4...
$ Year1   (dbl) 1894, 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903,...NULL
于 2014-03-18T09:19:31.787 回答
8

dplyr具有自己的dplyr对象打印功能。在这种情况下,作为操作结果的对象是tbl_df. 匹配的打印函数是dplyr:::print.tbl_df。这表明trunc_mat该函数负责打印而不是打印什么,包括哪些变量。

遗憾的是,dplyr:::print.tbl_df它不传递任何参数,trunc_mat也不trunc_mat支持选择显示哪些变量(仅显示多少行)。一种解决方法是将 dplyr 的结果转换为 adata.frame并使用head

res = movies %.% 
 group_by(year) %.% 
 summarise(Length = mean(length), Title = max(title), 
  Dramaz = sum(Drama), Actionz = sum(Action), 
  Action = sum(Action), Comedyz = sum(Comedy)) %.% 
 mutate(Year1 = year + 1)

head(data.frame(res))
  year    Length                       Title Dramaz Actionz Action Comedyz
1 1898  1.000000 Pack Train at Chilkoot Pass      1       0      0       2
2 1894  1.000000           Sioux Ghost Dance      0       0      0       0
3 1902  3.555556     Voyage dans la lune, Le      1       0      0       2
4 1893  1.000000            Blacksmith Scene      0       0      0       0
5 1912 24.382353            Unseen Enemy, An     22       0      0       4
6 1922 74.192308      Trapped by the Mormons     20       0      0      16
  Year1
1  1899
2  1895
3  1903
4  1894
5  1913
6  1923
于 2014-03-18T05:50:59.537 回答
1

所以,这有点老了,但我在寻找相同问题的答案时发现了这一点。我想出了这个解决方案,它秉承了管道的精神,但在功能上与公认的答案相同(请注意,管道符号%.%已被弃用,取而代之的是%>%

movies %>% 
    group_by(year) %>% 
    summarise(Length = mean(length), Title = max(title), 
    Dramaz = sum(Drama), Actionz = sum(Action), 
    Action = sum(Action), Comedyz = sum(Comedy)) %>% 
    mutate(Year1 = year + 1) %>%
    as.data.frame %>%
    head
于 2014-08-13T04:54:45.493 回答
1

movies %.% group_by(year) %.% ....... %.% print.default

dplyr使用,而不是默认的打印选项,dplyr:::print.tbl_df以确保您的屏幕不会因大量数据集而过载。当你最终将你的东西缩减到你想要的并且不想再从自己的错误中拯救出来时,只要坚持print.default到底,把所有东西都吐出来。


顺便说一句,methods(print)显示有多少包需要编写自己的print函数(想想,例如,igraph或者xts--- 这些是新的数据类型,所以你需要告诉他们如何在屏幕上显示)。

HTH 下一个谷歌用户。

于 2015-05-01T04:31:31.153 回答