I have heard that for loops are bad R style. I have a for loop that uses "list" to assemble the output, and even if the control flow of "for" is tolerable, the output is not very readable.

Here is my original code:

```
longlist<-c("apple","orange","red snapper")
sublist<-c("ap","er")

altgrepper1<-function(substringList, longstringList){
  #go through the list of short strings 
  #check to see whether any of the short strings is a substring
  #of any of the long strings
  output2<-NULL
  for (i in 1:length(substringList)){  
      output1<-grep(substringList[i],longstringList)  
    output2<-list(output2,output1)
  }
  output2
}

```

Here is the output:

```
[[1]]
[[1]][[1]]
NULL

[[1]][[2]]
[1] 1 3

[[2]]
[1] 3

```

I am very surprised that the output has anything preceding the NULL, so clearly I don't understand how list works. This output makes sense to me on a toy example, but I'm sure I would rapidly get confused if I tried to understand output from a real data set.

So perhaps the highest priority is to return a better-structured sort of output - perhaps a list, perhaps an array. But to do that, it might be better to eliminate the for loop and use lapply or some other R syntax.

I'm sorry for the newbie question, but I really don't see why my output looks this way.