R-users,

I have the following piece of code which I am trying to run on a dataframe 
(aga2) with about a half million records.  While the code works, it is 
extremely slow.  I've read some of the help archives indicating that I should 
allocate space to the p1 and ags1 vectors, which I have done, but this doesn't 
seem to improve speed much.  Would anyone be able to provide me with advice on 
how I might be able to speed this up?


p1 <- character(dim(aga2)[1])
ags <- character(dim(aga2)[1])
for (i in 1:dim(aga2)[1])
{
 if (aga2$first.exon[i]==TRUE)
 {
  p1[i]<-as.character(aga2[i, "AP"])
  ags[i]<-as.character(aga2[i, "AS"])
  
 }
 else 
 {
  p1[i]<-paste(p1[i-1], aga2[i, "AP"], sep=",")
  ags[i]<-paste(ags[i-1], aga2[i, "AS"], sep=",")
 }
}

Thanks.

--Mark Lamias


      
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to