[R] on how to make a skip-table

arun smartpink111 at yahoo.com
Fri Sep 13 02:10:21 CEST 2013


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
        2      4
        4      8
        7      9", sep="", header = TRUE)
 indx<-diff(valida.records$NR)-1
skip.table<- within(valida.records, {skip<- with(record.length,tapply(length,c(-1,rep(indx,indx+1)),function(x) sum(x[-length(x)])))})[,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 <zhangweiwu at realss.com>
To: r-help at r-project.org
Cc: 
Sent: Thursday, September 12, 2013 1:17 PM
Subject: [R] on how to make a skip-table


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 at 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.




More information about the R-help mailing list