[R] Faster way to zero-pad a data frame...?

From: Pete Cap <peteoutside_at_yahoo.com>
Date: Wed 31 May 2006 - 05:57:18 EST


Hello List,  

 I am working on creating periodograms from IP network traffic logs using the Fast Fourier Transform. The FFT requires all the data points to be evenly-spaced in the time domain (constant delta-T), so I have a step where I zero-pad the data.  

 Lately I've been wondering if there is a faster way to do this. Here's what I've got:  

*data2 is the zero-padded data frame. It has length equal to the greatest value of "time" in data2:
 time,events

 1,0
 2,0
 3,0
 4,0
 5,0
 6,0
 7,0
 8,0
 9,0

 10,0  

 So I run this for loop:
 for(i in 1:length(data1[,1])) {

     data2[data1[i,1],2]<-data1[i,2]
 }  

 Which goes to each row in data1, reads the timestamp, and writes the "events" to the corresponding row in data2. The result is:  time,events

 0,1
 1,30
 2,0
 3,0
 4,0
 5,14
 6,0
 7,0
 9,0
 9,0

 10,4  

 For a 24-hour log (86,400 seconds) this can take a while...Any advice on how to speed it up would be appreciated.  

 Thanks,
 Pete Cap                   


        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed May 31 06:03:05 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 31 May 2006 - 08:13:49 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.