[R] How to split a Spell Data Frame into long format (irregular episode length)

2014-03-22 Thread PabloNeruda
Dear R-Users and developers, I am used to work with singular data but now I have to get my data of an spell-data-frame conducted in a big German longitudinal survey. The data structure is: persnr spelltypbegin end xf105 10 1 5 xf105 1 6 15 xf106 4 7

Re: [R] How to split a Spell Data Frame into long format (irregular episode length)

2014-03-22 Thread arun
Hi, You could try: res - data.frame(dat[rep(1:nrow(dat),with(dat,end-begin+1)),1:2], month=unlist(apply(dat[,3:4],1,function(x) seq(x[1],x[2] row.names(res) - 1:nrow(res) A.K. On Saturday, March 22, 2014 6:29 AM, PabloNeruda s_ysi...@uni-bremen.de wrote: Dear R-Users and developers, I