0

I'm somewhat new to R so i apologize in advance if the answer to this question is obvious. I have a very long data frame (only one variable) from which i want to create multiple objects from subsets within the data frame. The code to scrape the data & format as data frame 'aa', define the variable as 'whatever':

aa<-data.frame(readLines("ftp://ftp.cmegroup.com/pub/settle/stlint"))
aa<-data.frame(aa[-1:-3,])
colnames(aa)<-"whatever"

I am looking to subset each section under a heading beginning with 'ZE' and ending with the last data row before the next 'ZE' or before the 'TOTAL'... so basically i want 36 objects (length(grep("ZE",aa$whatever[1:nrow(aa)]))=36) each starting with their respective 'ZE' title followed by (roughly) 70 rows of data, with each object identified by their respective title. So for instance, I would want the first dataset (headed by row ZE MAR15 EURODOLLAR OPTIONS CALL) to be named some variant of 'March 2015 Calls' as i just need to denote the month, year, and whether the data is for calls or puts.

I can actually code this up in batch thru a loop, but here's my problem: right now of course the first 'ZE' month is Mar15, ie March 2015, and the last 'ZE' month is Dec18, or Dec 2015. This will change as time goes on though, and i'm hoping to be able to automatically name them based on the first line without tweaking the script when the months change for each contract. So is it possible to flexibly name each of these subsets based on the content of the header?

Thanks

pmandersen
  • 23
  • 1
  • 3
  • This has been asked and answered (at least twice and possibly more often) on SO before. Try some searching. – IRTFM Feb 25 '15 at 05:25
  • I have searched but have not been able to find it. I suspect I am using the wrong keywords. If you let me know what specific term to search, i'd appreciate it. – pmandersen Feb 25 '15 at 16:11

0 Answers0