How to find datatype of a variable in R?

This recipe helps you find datatype of a variable in R

Recipe Objective**

How to find the data type of a variable in R? Variables are reserved memory locations used to store values. Variables can be of different types known as data types such as numeric, integer, character, boolean, etc. Variables are assigned to R-objects and the data type of R-objects are the data types of a variable. class () , typeof () , mode () some of the functions which help determine the data type of vector. This recipe demonstrates how to find the data type of any vector input value using different functions.

Getting Started with Image Segmentation using Mask R-CNN

Step 1 -Create input vectors

x <- "Hello World" y <- 3 z <- 53L

Stpe 2 - Use class() function

print(paste("class of x is : ",class(x)))

 "Output is" : character 

print(paste("class of y is : ",class(y)))

 "Output is" : numeric

print(paste("class of z is : ",class(z)))

 "Output is ": integer

Step 3 - Use typeof() function

print(paste("type of x is : ",typeof(x)))

 "Output is" : character

Step 4 - Use mode() function

print(paste("mode of x is : ",mode(x)))

 "Output is" : character

What Users are saying..

profile image

Anand Kumpatla

Sr Data Scientist @ Doubleslash Software Solutions Pvt Ltd
linkedin profile url

ProjectPro is a unique platform and helps many people in the industry to solve real-life problems with a step-by-step walkthrough of projects. A platform with some fantastic resources to gain... Read More

Relevant Projects

OpenCV Project to Master Advanced Computer Vision Concepts
In this OpenCV project, you will learn to implement advanced computer vision concepts and algorithms in OpenCV library using Python.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Classification Projects on Machine Learning for Beginners - 1
Classification ML Project for Beginners - A Hands-On Approach to Implementing Different Types of Classification Algorithms in Machine Learning for Predictive Modelling

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.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Isolation Forest Model and LOF for Anomaly Detection in Python
Credit Card Fraud Detection Project - Build an Isolation Forest Model and Local Outlier Factor (LOF) in Python to identify fraudulent credit card transactions.

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.

Text Classification with Transformers-RoBERTa and XLNet Model
In this machine learning project, you will learn how to load, fine tune and evaluate various transformer models for text classification tasks.

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.