Re: [R] Column order in stacking/unstacking

From: Peter Ehlers <>
Date: Sat, 12 Mar 2011 03:09:24 -0800

On 2011-03-12 02:01, Dennis Murphy wrote:
> Hi:
> It would help if you named your variables such that alphanumeric ordering
> doesn't disturb your variable ordering. Having been burned by this a few
> times, I've learned the basics of sprintf() :) Here's your example
> revisited, along with an alternative stacking/unstacking display with
> package reshape.
> library(reshape)
> vnames<- paste('X', sprintf('%02d', c(1, 2, 10)), sep = '')
>> vnames
> [1] "X01" "X02" "X10"


You can do this a bit more simply with sprintf:

  vnames <- sprintf("%s%02d", "X", c(1, 2, 10))

Peter Ehlers mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sat 12 Mar 2011 - 11:33:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Mar 2011 - 11:50:21 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive