Q:

Convert Year/Quarter Data Frame to Time Series

I am new to R and need to do a time series analysis.  My data is currently in a data frame.  The appropriate format for time series analysis appears to be ts or xts, depending on which article you read.  I was only able to figure out how to reach xts form by the information I found.
My questions are:
Question 1: How can I convert my data frame to a ts?
Question 2: What is a better way to convert my data frame to xts than what I've done? 

What I Did
The time series data needs to contain the variable of interest x3 along with a categorical variable.  The series should be given by year-quarter.
The data looks similar to this:
df <- data.frame(id = sprintf("%03d", 1:13),
                      year = c(2011, rep.int(2012,4), rep.int(2013,4), rep.int(2014,4)),
                      qtr = rep_len(c(4,1:3),13),
                      cat = sample(1:5, size=13, replace = TRUE),
                      x1 = sample.int(13)/100,
                      x2 = sample.int(13)/100,
                      x3 = sample.int(13)/100)

df
    id year qtr cat   x1   x2   x3
1  001 2011   4   4 0.10 0.05 0.11
2  002 2012   1   2 0.06 0.09 0.10
3  003 2012   2   1 0.12 0.02 0.03
4  004 2012   3   5 0.13 0.08 0.05
5  005 2012   4   1 0.04 0.06 0.04
6  006 2013   1   5 0.03 0.13 0.06
7  007 2013   2   4 0.05 0.12 0.12
8  008 2013   3   2 0.09 0.03 0.09
9  009 2013   4   4 0.11 0.01 0.13
10 010 2014   1   1 0.01 0.10 0.08
11 011 2014   2   2 0.08 0.07 0.07
12 012 2014   3   5 0.02 0.11 0.01
13 013 2014   4   3 0.07 0.04 0.02

The code I wrote to convert it to xts is as follows:
library(zoo)
library(xts)

yq <- paste(df$year, "-", df$qtr, sep="")
df.yq <- cbind(df, as.yearqtr(yq))
df.xts <- xts(df.yq[,"x3"], order.by = df.yq[,"as.yearqtr(yq)"])
df.xts <- cbind(df.xts, df[,"cat"])
names(df.xts) <- c("x3", "cat")

This outputs:
> df.xts
          x3 cat
2011 Q4 0.11   4
2012 Q1 0.10   2
2012 Q2 0.03   1
2012 Q3 0.05   5
2012 Q4 0.04   1
2013 Q1 0.06   5
2013 Q2 0.12   4
2013 Q3 0.09   2
2013 Q4 0.13   4
2014 Q1 0.08   1
2014 Q2 0.07   2
2014 Q3 0.01   5
2014 Q4 0.02   3

I do not think that my solution introduces any inconsistencies, but it feels "hacky."  My question is as much about good form as it is learning data manipulation.  Any information you can give me would be much appreciated.

A:

1) Convert it first to zoo and from there as.xts and as.ts will work:
z <- with(df, zoo(cbind(x3, cat), as.yearqtr(year + (qtr-1)/4)))
x <- as.xts(z) # omit this line if you don't need x; can also omit library(xts)
tt <- as.ts(z)

1a) This variation also works:
x <- with(df, xts(cbind(x3, cat), as.yearqtr(year + (qtr-1)/4)))
tt <- as.ts(as.zoo(x))

2) If you are only interested in ts then this does not use any packages but does assume that the data is in order and there are no missing quarters:
tt <- with(df, ts(cbind(x3, cat), start = c(year[1], qtr[1]), freq = 4))

UPDATE Simplified (2).

