Instead of looping on each row, try the following p1 <- as.character(aga$AP) # skew by one on the paste p1 <- ifelse(aga2$first.exon, p1, paste(c("", tail(ags, -1)), aga2$AP, sep=','))
ags <- as.character(aga$AS) ags <- ifelse(aga2$first.exon, ags, paste(c("", tail(ags, -1)), aga2$AS, sep=',') On Tue, May 11, 2010 at 12:17 PM, Mark Lamias <mlam...@yahoo.com> wrote: > 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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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.