Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding "Variables not shown" in dplyr, to display all columns from df

When I have a column in a local data frame, sometimes I get the message Variables not shown such as this (ridiculous) example just needed enough columns.

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) 

I want to see Year1! How do I see all the columns, preferably by default.

like image 290
Hugh Avatar asked Mar 18 '14 05:03

Hugh


People also ask

What does %>% do in dplyr?

%>% is called the forward pipe operator in R. It provides a mechanism for chaining commands with a new forward-pipe operator, %>%. This operator will forward a value, or the result of an expression, into the next function call/expression. It is defined by the package magrittr (CRAN) and is heavily used by dplyr (CRAN).

What dplyr function can you use to pull out certain columns from a dataset in R?

Select certain columns in a data frame with the dplyr function select . Extract certain rows in a data frame according to logical (boolean) conditions with the dplyr function filter .

How do I select variables in dplyr?

How To Select A Variable by name with dplyr select()? We can select a variable from a data frame using select() function in two ways. One way is to specify the dataframe name and the variable/column name we want to select as arguments to select() function in dplyr.

Does dplyr work with data frame?

All of the dplyr functions take a data frame (or tibble) as the first argument. Rather than forcing the user to either save intermediate objects or nest functions, dplyr provides the %>% operator from magrittr. x %>% f(y) turns into f(x, y) so the result from one step is then “piped” into the next step.


2 Answers

There's (now) a way of overriding the width of columns that gets printed out. If you run this command all will be well

options(dplyr.width = Inf) 

I wrote it up here.

like image 73
Mark Needham Avatar answered Sep 18 '22 18:09

Mark Needham


You might like 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 
like image 34
Romain Francois Avatar answered Sep 20 '22 18:09

Romain Francois