r - Split a database by regular time intervals (6 months each = 131 days) -


i'm beginner r please excuse me advance if question seems basic i'm quite lost between functions can used split database (lubridate, split, daply...).

my data composed stock market index' daily returns 1978 2017. regress y1 on x1, x2, x3 , x4 every 6 months. information, there 262 observations each year. 6 months = 131 trading days.

here extract of (excel) database:

date	y1	x1	x2	x3	x4  01/06/78	-0,054728735	0,062336581	-0,017447642	0,018066145	0,0137291  01/09/78	-0,0633203	0,051713026	-0,025691177	-0,006909645	-0,015750265  01/10/78	-0,048852901	0,026756766	-0,00910902	-0,013302491	-0,025715185  01/11/78	-0,049357647	0,013119868	-0,005255487	-0,008035708	-0,01565239  01/12/78	-0,044503679	-0,029061109	-0,016565941	-0,01131818	-0,008933417  01/13/78	-0,027863545	-0,044460617	-0,012819194	-0,021071992	-0,015533829  01/16/78	-0,026495125	-0,056336531	-0,007379243	-0,003360595	0,01056797  01/17/78	-0,007670981	-0,041300771	0	-0,00111657	0,019498044  01/18/78	0,000662032	-0,031227275	0,003506725	-0,018967432	-0,003861009

i think best way (i) split database every 6 months, (ii) make linear regression on each 6 month segment.

could tell me if best way, according you? if case show me code split database every 6 month?

thanks lot help!

you create sequence of numbers cooresponding rows of data:

i = c(seq(1,nrow(dat),by=131),nrow(dat)) 

and use lapply split data:

lapply(seq_along(i)[-length(i)],function(x) dat[i[x]:(i[x+1]-1),]) 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -