Re: [R] on how to make a skip-table

2013-09-17 Thread gildororonar
Quoting "Zhang Weiwu" : Jim Holtman asked me to elaborate the problem: It is a common problem in reading sparse variable-lenght record data file. Records are stored in file one next to another. The length of each record is known in advance, but a lot of them records are invalid,

Re: [R] on how to make a skip-table

2013-09-12 Thread Zhang Weiwu
It is a nice surprise to wake up receiving three answers, all producing correct results. Many thanks to all of you. Jim Holtman solved it with amazing clarity. Gang Peng using a traditioanl C-like pointer style and Arun with awesome tight code thanks to diff(). I am embrassed to see my mis-

Re: [R] on how to make a skip-table

2013-09-12 Thread arun
HI, May be this helps: record.length <- read.table(text = "NR    length     1  100     2  130     3  150     4  148     5  100     6    83     7    60", sep="",header = TRUE)  valida.records <- read.table(text = "NR    factor     1  3

Re: [R] on how to make a skip-table

2013-09-12 Thread Gang Peng
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 > > I've got two data frames, as shown below: > (NR means Number of Record) > > record.lenths >> >

Re: [R] on how to make a skip-table

2013-09-12 Thread jim holtman
try this: > record.length <- read.table(text = "NR length + 1 100 + 2 130 + 3 150 + 4 148 + 5 100 + 683 + 760", header = TRUE) > valida.records <- read.table(text = " NR factor +