I have a list of geneids. (1024, 284, 526). I have their pertaining sequences in in a file (represented as ff). I extracted the names(ff) in desc. the file ff could contain a geneid multiple times. My loop only extracts the first hit (only 1 sequence). I want to extract all the sequences that match my gene id (could more than one sequence). file ff could contain (1024, 1024, 1024, 284, 526). I want to extract all the three sequences with the id 1024. But my loop extracts only the first 1024
for(i in 1:length(geneids)){
   temp<- ff[match(geneids[i],as.numeric(gsub("\\_.*","", desc)))]
   subset.seq <- c(subset.seq,temp) 
   subset.seq<-subset.seq[!sapply(subset.seq, is.null)]
   #print(subset.seq)
   temp1 <- names(temp)
   temp2 <-c(sapply(temp, function(x) x))
   s2 <- c(s2,temp1)
   s1 <- c(s1,temp2)
i <- i + 1}
