n.record <- length(record.lenths$NR) index <- record.lenths$NR %in% valida.records$NR tmp <- 1:n.record ind <- tmp[index] st <- 1 skip <- rep(0,length(ind)) for(i in 1:length(ind)){ if(st<ind[i]){ skip[i]<-sum(record.lenths$ length[st:(ind[i]-1)]) } st <- ind[i]+1 }
2013/9/12 Zhang Weiwu <zhangwe...@realss.com> > > I've got two data frames, as shown below: > (NR means Number of Record) > > record.lenths >> > NR length > 1 100 > 2 130 > 3 150 > 4 148 > 5 100 > 6 83 > 7 60 > > valida.records >> > NR factor > 1 3 > 2 4 > 4 8 > 7 9 > > And I intend to obtain the following skip-table: > > skip.table >> > NR skip factor > 1 0 3 > 2 0 4 > 4 150 8 > 7 183 9 > > > The column 'skip' is the space needed to skip invalid records. > > For example, the 3rd element of skip.table has skip of '150', intended to > skip the invalid record No.3 in record.lengths > > For example, the 4th element of skip.table has skip of '183', intended to > skip the invalid record No.5 and No.6, together is 100+83. > > It's rather apparently intended for reading huge data files, and looks > simple math, and I admit I couldn't find an R-ish way doing it. > > Thanks in advance and also thanks for pointing out if I had been on the > right track to start with. > > ______________________________**________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/**listinfo/r-help<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. > [[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.