r - Separating rows containing values -


so have huge data set of on 500,000 different rows need separate. each row set of numbers such this:

p040120000000000000000001001101210000000120000000000 

the important thing note here "p04012" section corresponds 1 specific table. few hundred thousand items down, code transforms this:

p051120150000000000000002158101110000000210000184380 

with "p05112015" meaning different. first 8-10 characters each string of numbers corresponds table, of right lumped 1 huge dataset 1 column , 500,000 rows. how separate rows specific tables based on numbers?

i plan use read.fwf split number strings columns, @ point figuring out how split them tables.

here's 1 possibility might work uses read.fwf():

options(stringsasfactors = f)  # fake data file tf <- tempfile() x <- cat(   "p040120000000000000000001001101210000000120000000000",   "p051120150000000000000002158101110000000210000184380",   sep = "\n",   file = tf)  # table identifiers using read.fwf() ids <- read.fwf(tf, widths = c(10, 42))  # drop trailing zeros (not sure if important) ids <- gsub("0+$", "", ids$v1) 

Comments