Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

r
tables

What is the kable() method in R?

Fahad Akhtar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Overview

kable() is a method in R designed to generate a table against the given input. It is a part of the knitr package, which should be installed in the R environment for the kable method to run.

Syntax

kable(data)

Parameters

The input (data) for the kable function is an R object or a data frame.

Return value

kable returns a table for a data object. If the input is a list of objects, it returns a table containing multiple tables.

Example

Let’s look at an example of the kable function.

library(knitr) #Importing the library for kable()
my_basket = data.frame(
#Column 01
ITEM_GROUP = c("Fruit","Fruit","Fruit",
"Vegetable","Vegetable","Vegetable",
"Dairy","Dairy","Dairy"),
#Column 02
ITEM_NAME = c("Apple","Banana","Orange",
"Carrot","Potato","Brinjal",
"Milk","Cheese","Cream"),
#Column 03
Price = c(100.981, 80.643, 65.3,
71.9, 62.2, 71.3,
25.1, 62.9, 41.9))
#Function call
kable(my_basket)
Example code for kable

Explanation

  • Line 1: We include the package which is required by the kable function in order to run.

  • Lines 3 to 17: We generate our data frame.

  • Line 20: We call the kable function to generate the table for our data frame.

RELATED TAGS

r
tables

CONTRIBUTOR

Fahad Akhtar
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring