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.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
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

0
Votes
1
Answer

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.
Code:
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]
 
Best, 
Eli

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

2 months
×
Learn Data Science
this Summer!
Get 50% OFF