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

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

Time Series Python Project using Greykite and Neural Prophet
In this time series project, you will forecast Walmart sales over time using the powerful, fast, and flexible time series forecasting library Greykite that helps automate time series problems.

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.

NLP Project for Beginners on Text Processing and Classification
This Project Explains the Basic Text Preprocessing and How to Build a Classification Model in 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.

Build a Similar Images Finder with Python, Keras, and Tensorflow
Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

Build Regression Models in Python for House Price Prediction
In this Machine Learning Regression project, you will build and evaluate various regression models in Python for house price prediction.

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data

Build a Autoregressive and Moving Average Time Series Model
In this time series project, you will learn to build Autoregressive and Moving Average Time Series Models to forecast future readings, optimize performance, and harness the power of predictive analytics for sensor data.

Build a Music Recommendation Algorithm using KKBox's Dataset
Music Recommendation Project using Machine Learning - Use the KKBox dataset to predict the chances of a user listening to a song again after their very first noticeable listening event.

End-to-End Snowflake Healthcare Analytics Project on AWS-1
In this Snowflake Healthcare Analytics Project, you will leverage Snowflake on AWS to predict patient length of stay (LOS) in hospitals. The prediction of LOS can help in efficient resource allocation, lower the risk of staff/visitor infections, and improve overall hospital functioning.