chaseking123 chaseking123 - 2 months ago 21
R Question

R- For loop for non-sequential list

This is probably a simple question, but I'm struggling finding a way to do the equivalent of "for (i in 1:10){ do something}" but with a list of strings. For example:

given a list of strings a = ("Joe", "John", "George") I'd want to do the following:

for (a in "Joe":"George"){
url <- paste0(", a)

and have the function traverse through the list of names and hit the url with each name.


You'd go with for (i in 1:length(a)) { etc } but yeah getting your head around apply functions is generally preferable for speed reasons.