🛠️ Scheduled Maintenance | We’ll be undergoing scheduled maintenance and upgrades between 00:00 PST Jan 26th until 00:00 PST Jan 28th. There may be brief interruption of services in that period. We apologize for the inconvenience.

The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Anybody can ask a question
Anybody can answer
The best answers are voted up and moderated by our team

For loop on R – Only first word is repreated

For loop on R – Only first word is repreated


Hi, I was just following the same syntax as done by you in the video for “for loop” and I am getting only the first word inserted in the new.title.
for(i in 1:5){
new.title[i] <- title[1]
Console Output:
for(i in 1:5){
+ new.title[i] <- title[1]
+ }
> new.title
[1] “Catch” “Catch” “Catch” “Catch” “Catch”
What am I doing worng?

1 Answer

365 Team

Hi Srajan, 
thanks for reaching out!
In the second line of code, instead of title[1] you should feed the i-th title, otherwise it would always be the first element. Like so:
new.title[i] <- title[i]

Oh. So sorry. It was a very silly mistake. I didn’t notice that I had place “1” instead of “i”.

9 months