Re: [R] reshaping pairs of columns

2009-11-03 Thread jim holtman
Try this: require(reshape) # melt the data x - melt(maps, id='point') # split out the labels labels - do.call(rbind, strsplit(sub((.*)(.), \\1 \\2, x$variable), ' ')) x$source - labels[, 2] x$variable - labels[, 1] cast(x, point + source ~ variable) point sourcelat long 1 1

[R] reshaping pairs of columns

2009-11-03 Thread Michael Friendly
Given a data frame consisting of a pointID and 12 pairs of (lat, long) variables, with names latA, longA, latB, longB, ... latL, longL, I want to reshape it into a data frame with the structure point source lat long 1A ... ... 1B ...... I've looked at

Re: [R] reshaping pairs of columns

2009-11-03 Thread Phil Spector
Michael - I think this call to reshape gets you pretty close: reshape(maps,direction='long', + varying=list(grep('lat',names(dat),value=TRUE), + grep('long',names(dat),value=TRUE)), + times=LETTERS[1:12]) point time latA longA id 1.A 1A