What is a tibble in R

This recipe explains what is a tibble in R

Recipe Objective

What is a tibble in R

tibble() prints the data of dataset in the similar way, a dataframe() does. tibble() is a new form / version of the usual dataframe(), which is part of the tidyverse library. tibble() returns the values of a dataset in a much more efficient format then the dataframe() tibble() returns the values of the defined columns along with their datatype while dataframe() only prints the elements. Also, the tibble functions prints the size of the dataset - number of rows and columns. Various formats in which the tibble function can be used- tibble() - to create a new tibble as_tibble() - To create a tibble by passing an existing dataframe This recipe demonstrates an example on what is tibble and how to use the tibble in R.

Step 1 - Install the required library

library(tidyverse)

Step 2 - Create a dataframe

df <- data.frame(x = c("A","B","C","D","E"), y = c(10,20,30,40,50)) print(df)

"Dataframe is:"
  x  y
1 A 10
2 B 20
3 C 30
4 D 40
5 E 50

Step 3 - Use as_tibble()

tib <- as_tibble(df) print(tib)

"Output of code is:"
# A tibble: 5 x 2
  x         y
   
1 A        10
2 B        20
3 C        30
4 D        40
5 E        50

Step 4 - Use tibble()

student_name <- c("John","Sia","Zen","Victor","Wanda") student_id <- c("112,115,117,113,119") math_marks <- c(58,36,47,98,78) sci_math <- c(98,78,63,45,55) student_info <- tibble(student_name,student_id,math_marks,sci_math) print(student_info)

"Output of code is:"
# A tibble: 5 x 4
  student_name student_id          math_marks sci_math
                                  
1 John         112,115,117,113,119         58       98
2 Sia          112,115,117,113,119         36       78
3 Zen          112,115,117,113,119         47       63
4 Victor       112,115,117,113,119         98       45
5 Wanda        112,115,117,113,119         78       55

{"mode":"full","isActive":false}

What Users are saying..

profile image

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Build CNN Image Classification Models for Real Time Prediction
Image Classification Project to build a CNN model in Python that can classify images into social security cards, driving licenses, and other key identity information.

MLOps Project to Build Search Relevancy Algorithm with SBERT
In this MLOps SBERT project you will learn to build and deploy an accurate and scalable search algorithm on AWS using SBERT and ANNOY to enhance search relevancy in news articles.

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

Build Regression (Linear,Ridge,Lasso) Models in NumPy Python
In this machine learning regression project, you will learn to build NumPy Regression Models (Linear Regression, Ridge Regression, Lasso Regression) from Scratch.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Learn How to Build a Logistic Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple logistic regression model in PyTorch for customer churn prediction.

Classification Projects on Machine Learning for Beginners - 2
Learn to implement various ensemble techniques to predict license status for a given business.

Stock Price Prediction Project using LSTM and RNN
Learn how to predict stock prices using RNN and LSTM models. Understand deep learning concepts and apply them to real-world financial data for accurate forecasting.

Build a Review Classification Model using Gated Recurrent Unit
In this Machine Learning project, you will build a classification model in python to classify the reviews of an app on a scale of 1 to 5 using Gated Recurrent Unit.

Build Classification Algorithms for Digital Transformation[Banking]
Implement a machine learning approach using various classification techniques in Python to examine the digitalisation process of bank customers.