Tibble is a package in the R programming language that is used to manipulate and print data frames. It is the latest method for reimagining a data frame. It keeps all the crucial features regarding the data frame.
There are two main differences between Tibbles and the data frame:
Tibble has a more advanced print function. It shows only the first ten rows with all the columns that can be fit on the screen. Each column also shows the data types. It helps to avoid printing too much data automatically.
We can use the indexing for Tibbles in multiple ways:
df$y
df[["y"]]
df[[1]]
The pipe can also be used for submitting:
df %>% .$y
df %>% .[["y"]]
In the code snippet below, we have a data frame as a record of an employee:
# Creating the data frame.employee <- data.frame(employee_id = c (1:5),employee_name = c("JOHN","TIM","STARC","HARRY","TINA"),employee_salary = c(567.3,675.2,674.0,678.0,790.25),# employee starting datestarting_date = as.Date(c("2015-03-03", "2016-08-02", "2018-11-12", "2021-07-21","2016-01-06")),stringsAsFactors = FALSE)# Printing the data frame.print(employee)
data.frame()
method.employee
data frame include employee_id
, employee_name
, employee_salary
, and starting_date
.employee
data frame to the console.In the code snippet below, we have a Tibble from tidyverse
package:
# Program for tibble implementationlibrary("dplyr", warn.conflicts = FALSE)Section<-rep(c("A","B","C","D","E"),times=10)Ranking<-sample(1:10,50,replace=TRUE)dataframe<-data.frame(Section,Ranking)# first 5 entries of tibblehead(dataframe,5)# 5 entries from tail of tibbletail(dataframe,5)mylist <- dataframe %>% dplyr::group_by(Section,Ranking) %>% dplyr::mutate(count=n())print(mylist)
dplyr
library.Section
name. The rep()
function will replicate vector or list to N
times, that is, times=10
.Ranking
name. The sample()
function will return 50 samples with values from 1 to 10, that is, 1:10
.dataframe
, using the vectors we created above (Section, Ranking)
.n()
function.