Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

head() function in R package dplyr

Tags:

r

dplyr

This is a minor issue but in R when you type head(data.frame) you get the first few records from all the columns displayed. In the dplyr package the head function has been altered to only show the columns that can fit in your console window. This is often nice, but often I want to see the first few records for all the columns. Is there a way to tell head (in dplyr) to show all columns without converting the tbl.df/data.frame to a data.frame (and I prefer head to str()).

Thanks!

ZR

like image 321
ZRoss Avatar asked May 01 '14 13:05

ZRoss


People also ask

What does head () do in R?

The head() function in R is used to display the first n rows present in the input data frame.

What package is dplyr in R?

The dplyr package in R Programming Language is a structure of data manipulation that provides a uniform set of verbs, helping to resolve the most frequent data manipulation hurdles.

What does the head function do?

head () function is used to access the first n rows of a dataframe or series. It returns a smaller version of the caller object with the first few entries. In this article, you will learn how to use the python head function , customizing the number of entries and two more functions that do the same job differently.


2 Answers

you can now use the glimpse() verb in dplyr 0.2 :

from https://github.com/hadley/dplyr/releases :

"glimpse() makes it possible to see all the columns in a tbl, displaying as much data for each variable as can be fit on a single line."

like image 174
npjc Avatar answered Sep 19 '22 14:09

npjc


As Arun said, it's because of the print.tbl_df method. Just do:

print.data.frame(head(your_dplyr_dataframe))
like image 45
Karl Forner Avatar answered Sep 18 '22 14:09

Karl Forner