How to convert float to integer in R?

This recipe helps you convert float to integer in R

Recipe Objective

How to convert float to integer in R? When a data type is converted to another data type, it is known as data type casting. Data type casting is necessary when an output returned is a data type different than what we need to perform any further operations. There are different types of data types like integer, float, character, etc. Integers are described as whole numbers, whereas float describes a number as a decimal type. This recipe converts a float value to an integer value using as.integer () function.

Access YOLO OCR Character Recognition Project with Source Code

Step 1 - Define a float vector

x <- 4.5

Step 2 - Convert float to integer

Removes the decimal part and converts into integer

y=as.integer(x) print(paste("Float to Integer is:",y)) class(y)

"Output of the code is:Float to Integer is: 4"

What Users are saying..

profile image

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Predictive Analytics Project for Working Capital Optimization
In this Predictive Analytics Project, you will build a model to accurately forecast the timing of customer and supplier payments for optimizing working capital.

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 CNN for Image Colorization using Deep Transfer Learning
Image Processing Project -Train a model for colorization to make grayscale images colorful using convolutional autoencoders.

MLOps Project for a Mask R-CNN on GCP using uWSGI Flask
MLOps on GCP - Solved end-to-end MLOps Project to deploy a Mask RCNN Model for Image Segmentation as a Web Application using uWSGI Flask, Docker, and TensorFlow.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

ML Model Deployment on AWS for Customer Churn Prediction
MLOps Project-Deploy Machine Learning Model to Production Python on AWS for Customer Churn Prediction

Learn to Build an End-to-End Machine Learning Pipeline - Part 1
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, addressing a major challenge in the logistics industry.

Build a Wealth Management Agentic AI Chatbot with MS Fabric
In this Agentic AI project , you will learn to build an intelligent financial assistant that autonomously analyzes your financial data, assesses risks, and designs personalized investment strategies, making wealth management more efficient and personalized to your needs

PyCaret Project to Build and Deploy an ML App using Streamlit
In this PyCaret Project, you will build a customer segmentation model with PyCaret and deploy the machine learning application using Streamlit.

Build an AI Quiz Generator from Video with OpenAI API
In this LLM project, you will build a model to automate the transcription of video content and generate interactive quizzes using OpenAI’s Whisper and GPT-4o.

OSZAR »