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
)))})[,c(1,3,2)] skip.table   NR skip factor #1  1    0  3 #2  2    0  4 #3  4  150  8 #4  7  183  9 A.K. - Original Message - From: Zhang Weiwu To: r-help@r-project.org Cc: Sent: Thursday, September 12, 2013 1:17 PM Subject: [R] on how to make a skip-table I'

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 +

[R] on how to make a skip-table

2013-09-12 Thread Zhang Weiwu
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 683 760 valida.records NR factor