Resolved: 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.
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?
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 answers ( 0 marked as helpful)
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