Explain about initialize() function in R?

This recipe explains what about initialize() function in R

Recipe Objective

When we declare an object in R, the object can be classified either as public data element or private data element. Initialise is a function used to initialise a variable in the form of private data element ​

This recipe demonstrates how to initilise any values to the objects at the time of declaration of the objects. ​

STEP 1: Creating a user defined class

We do that by inclusisng public and private data members ​

library(R6) football <- R6Class( "Football", private = list( name_of_player = NA, goals_scored = NA), public = list( initialize = function(x,y){ private$name_of_player <-x private$goals_scored <-y }) )

The above code means that we trying to initialise the values of "name_of_player" and "goals_scored" during the time of execution/declaration ​

STEP 2: Calling the function and initialising the values to objects

man_utd <- football$new("Paul Pogba", 11) man_utd

  Public:
    clone: function (deep = FALSE) 
    initialize: function (x, y) 
  Private:
    goals_scored: 11
    name_of_player: Paul Pogba

This means that we have succeeded in initialzing the values "Paul Pogba" to name_of_player and "11" to goals_scored. ​

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

Langchain Project for Customer Support App in Python
In this LLM Project, you will learn how to enhance customer support interactions through Large Language Models (LLMs), enabling intelligent, context-aware responses. This Langchain project aims to seamlessly integrate LLM technology with databases, PDF knowledge bases, and audio processing agents to create a comprehensive customer support application.

Detectron2 Object Detection and Segmentation Example Python
Object Detection using Detectron2 - Build a Dectectron2 model to detect the zones and inhibitions in antibiogram images.

Recommender System Machine Learning Project for Beginners-3
Content Based Recommender System Project - Building a Content-Based Product Recommender App with Streamlit

Personalized Medicine: Redefining Cancer Treatment
In this Personalized Medicine Machine Learning Project you will learn to classify genetic mutations on the basis of medical literature into 9 classes.

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.

Deploy Transformer BART Model for Text summarization on GCP
Learn to Deploy a Machine Learning Model for the Abstractive Text Summarization on Google Cloud Platform (GCP)

Llama2 Project for MetaData Generation using FAISS and RAGs
In this LLM Llama2 Project, you will automate metadata generation using Llama2, RAGs, and AWS to reduce manual efforts.

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

MLOps AWS Project on Topic Modeling using Gunicorn Flask
In this project we will see the end-to-end machine learning development process to design, build and manage reproducible, testable, and evolvable machine learning models by using AWS

Learn Hyperparameter Tuning for Neural Networks with PyTorch
In this Deep Learning Project, you will learn how to optimally tune the hyperparameters (learning rate, epochs, dropout, early stopping) of a neural network model in PyTorch to improve model performance.