Predictive Hacks

How to Add New Elements to Vectors in R using a for-loop

Let’s initialize a new vector called v:


We can append new elements in a for-loop using the concatenate function c. For this example, we will iterate from 1 to 10 and we will take the power of two of each element, and we will append it to our vector v:


for (i in 1:10) {

 [1]   1   4   9  16  25  36  49  64  81 100

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore


Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.


Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s