Codementor Events

R lang : handy table functions

Published Mar 24, 2020
R lang : handy table functions

All starts with the data.

Read CSV file

mydata = read.csv("~/Downloads/sales.csv")

And if will output it, very probably it will look like a big mess
Screenshot 2020-03-24 at 12.59.24.png

Making table pretty

There are few way to make table pretty

  1. Use dplyr library
install.packages("dplyr")
library(dplyr)
  1. Convert dataframe to pretty dplyr dataframe
mydata = as_tibble(mydata)

Now mydata will look more structured, like this
Screenshot 2020-03-24 at 13.21.37.png

BUT we can see only first N rows. Which is not comfortable

OUTPUT all rows

print(tbl_df(mydata), n=500)
#n - number of rows

But still we can't see all fields. SO we can make another thing

DT package

It's a cool library which make comfortable table view

install.packages("DT")
library(DT)

datatable(mydata)

Now it will look pretty cool. So you can see all fields and paginate.
Screenshot 2020-03-24 at 13.32.54.png

Discover and read more posts from Alex Polymath
get started