Based on the DWin comment, you can try something like this:
read.clump <- function(file, lines, clump){ if(clump > 1){ header <- read.csv(file, nrows=1, header=FALSE) p = read.csv(file, skip = lines*(clump-1), #p = read.csv(file, skip = (lines*(clump-1))+1 if not a textConnection nrows = lines, header=FALSE) names(p) = header } else { p = read.csv(file, skip = lines*(clump-1), nrows = lines) } return(p) }
You should probably also add some error handling and function checking.
Then with
x = "letter1, letter2 a, b c, d e, f g, h i, j k, l" >read.clump(textConnection(x), lines = 2, clump = 1) letter1 letter2 1 ab 2 cd > read.clump(textConnection(x), lines = 2, clump = 2) letter1 letter2 1 ef 2 gh > read.clump(textConnection(x), lines = 3, clump = 1) letter1 letter2 1 ab 2 cd 3 ef > read.clump(textConnection(x), lines = 3, clump = 2) letter1 letter2 1 gh 2 ij 3 kl
Now you just need to * apply to clumps
source share