[R] reshape and split

Patrick Hausmann
Fri, 17 Dec 2004 10:47:58 -0000

Dear R-users,

I am trying to reshape the DF "dat2" in the "long" format,
but can't figure out how to use the "split"-option:

> dat2
   a.1995.z  b.1995.z  a.1996.z                    var
1 100.00000 100.00000 100.00000 Neue Anlagen insgesamt
2  40.09904  23.60890  40.88960      Neue Ausr??stungen
3  59.90096  76.39110  59.11040            Neue Bauten

This should be the result:

region	time	wz	value	var
a	1995	z	100	Neue Anlagen insgesamt
a	1995	z	40.09904	Neue Ausr??stungen
a	1995	z	59.90096	Neue Bauten
b	1995	z	100	Neue Anlagen insgesamt
b	1995	z	23.60890	Neue Ausr??stungen
b	1995	z	76.39110	Neue Bauten
a	1996	z	100	Neue Anlagen insgesamt
a	1996	z	40.88960	Neue Ausr??stungen
a	1996	z	59.11040	Neue Bauten

# Not working, sure "[.]" is missing
reshape(dat2, dir="long", varying=1:3,
split=list(regexp="[0-9][a-z]",
include=T))

Thanks for any help!
Patrick