What are [[ ]] used for in R?

This recipe explains what are [[ ]] used for in R

Recipe Objective

List is a data structure having components of mixed data types. We can include matrices, vectors data frames or lists in a list. R list is a container for values, its contents can be items of different data types.

Lists provide a convenient way to return the results of a statistical computation. ​

For example: Lst = list("name", list("Ram", "Shyam", "Dan")) ​

‘[‘ and ‘[[‘ are mainly used to access the elements of the lists. Hence, It is very important to distinguish Lst[[1]] from Lst[1]. ‘[[...]]’ is the operator used to select a single element, whereas ‘[...]’ is a general subscripting operator. Thus the former is the first object in the list Lst, and if it is a named list the name is not included. The latter is a sublist of the list Lst consisting of the first entry only. ​

If it is a named list, the names are transferred to the sublist. The names of components may be abbreviated down to the minimum number of letters needed to identify them uniquely. ​

This recipe demonstrates the use of "[[..]]" with an example. ​

Market Basket Analysis Project in Python with Real World Example

STEP 1: Create a list contaning sublists

Lst = list("name" = list("Ram", "Shyam", "Dan"), list(50,75,45))

STEP 2: Accessing the elements

To access the first element in the sublist named "name" ​

Lst[["name"]][1]

1. 'Ram'

This can also be accessed by using index: ​

Lst[[1]][1]

1. 'Ram'

But cannot be accessed by "[]" ​

Lst[1][1]

$name =
'Ram'
'Shyam'
'Dan''

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

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)

Build an AI Chatbot from Scratch using Keras Sequential Model
In this NLP Project, you will learn how to build an AI Chatbot from Scratch using Keras Sequential Model.

Build CI/CD Pipeline for Machine Learning Projects using Jenkins
In this project, you will learn how to create a CI/CD pipeline for a search engine application using Jenkins.

Learn Object Tracking (SOT, MOT) using OpenCV and Python
Get Started with Object Tracking using OpenCV and Python - Learn to implement Multiple Instance Learning Tracker (MIL) algorithm, Generic Object Tracking Using Regression Networks Tracker (GOTURN) algorithm, Kernelized Correlation Filters Tracker (KCF) algorithm, Tracking, Learning, Detection Tracker (TLD) algorithm for single and multiple object tracking from various video clips.

Build Time Series Models for Gaussian Processes in Python
Time Series Project - A hands-on approach to Gaussian Processes for Time Series Modelling in Python

Abstractive Text Summarization using Transformers-BART Model
Deep Learning Project to implement an Abstractive Text Summarizer using Google's Transformers-BART Model to generate news article headlines.

Loan Default Prediction Project using Explainable AI ML Models
Loan Default Prediction Project that employs sophisticated machine learning models, such as XGBoost and Random Forest and delves deep into the realm of Explainable AI, ensuring every prediction is transparent and understandable.

Azure Deep Learning-Deploy RNN CNN models for TimeSeries
In this Azure MLOps Project, you will learn to perform docker-based deployment of RNN and CNN Models for Time Series Forecasting on Azure Cloud.

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.

Learn to Build Generative Models Using PyTorch Autoencoders
In this deep learning project, you will learn how to build a Generative Model using Autoencoders in PyTorch