<font face="trebuchet ms,sans-serif">Caro Ivan,<br><br>Segue meu CMR de como entrar com os dados de data no formato mm-aa e criar um fator cujos níveis estejam na ordem cronológica. A (minha) jogada foi passar as strings mm-aa para dd-mm-aa e converter para as.Date, então converter para fator. No final, como exercício de expressão regular (tô aprendendo), transformei a representação dos níveis de aaaa-mm-dd para mm-aa assim como nos dados importados.<br>
<br><span style="font-family: courier new,monospace;">lines <- "trati dat vari</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 1 03-08 0.0000000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 1 04-08 0.3472222</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 1 05-08 0.0000000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 1 06-08 1.7361111</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 1 07-08 2.7777778</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 1 08-08 2.0833333</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 1 09-08 2.4305556</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 1 10-08 0.0000000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 1 11-08 0.0000000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 1 12-08 0.0000000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 1 01-09 0.0000000</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 1 02-09 26.7361111</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 1 03-09 70.4861111</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 1 04-09 99.3055556</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 1 05-09 99.3055556"</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">da <- read.table(textConnection(lines), header=TRUE, stringsAsFactors=FALSE);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">closeAllConnections()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">str(da)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">dat <- da$dat # joga para um vetor só para facilitar a manipulação</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">sort(dat) # ordenação alphanumerica feita na string</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">dat <- paste("01-", dat, sep="") # adiciona dia 01 a todas datas para ter dd-mm-aa</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">dat <- as.Date(dat, format="%d-%m-%y") # converte para vetor de datas</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">str(dat)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">format(dat, "%m-%y") # representa no formato mm-aa como entrou</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">plot(da$vari~dat) # gráfico sai na ordem correta das datas</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">plot(vari~factor(dat), da) # sai na ordem alphanumerica</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">dat.fac <- factor(dat) # passa datas para fator</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">levels(dat.fac) # níveis tem a ordem cronológica</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">plot(da$vari~dat.fac) # é fator mas sai na ordem correta</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">levels(dat.fac) <- gsub("\\d+(\\d{2})\\-(\\d+)\\-\\d+", "\\2\\-\\1",</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> levels(dat.fac)) # troca a represetação dos níveis</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">plot(da$vari~dat.fac) # com níveis mm-aa e na ordem correta</span><br style="font-family: courier new,monospace;"><br><br>À disposição.<br>
Walmes.<br><br clear="all"></font><span style="font-family: trebuchet ms,sans-serif;">==========================================================================</span><br style="font-family: trebuchet ms,sans-serif;"><span style="font-family: trebuchet ms,sans-serif;">Walmes Marques Zeviani</span><br style="font-family: trebuchet ms,sans-serif;">
<span style="font-family: trebuchet ms,sans-serif;">LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W)</span><br style="font-family: trebuchet ms,sans-serif;"><span style="font-family: trebuchet ms,sans-serif;">Departamento de Estatística - Universidade Federal do Paraná</span><br style="font-family: trebuchet ms,sans-serif;">
<span style="font-family: trebuchet ms,sans-serif;">fone: (+55) 41 3361 3573</span><br style="font-family: trebuchet ms,sans-serif;"><span style="font-family: trebuchet ms,sans-serif;">VoIP: (3361 3600) 1053 1173</span><br style="font-family: trebuchet ms,sans-serif;">
<span style="font-family: trebuchet ms,sans-serif;">e-mail: <a href="mailto:walmes@ufpr.br" target="_blank">walmes@ufpr.br</a></span><br style="font-family: trebuchet ms,sans-serif;"><span style="font-family: trebuchet ms,sans-serif;">twitter: @walmeszeviani</span><br style="font-family: trebuchet ms,sans-serif;">
<span style="font-family: trebuchet ms,sans-serif;">homepage: <a href="http://www.leg.ufpr.br/%7Ewalmes" target="_blank">http://www.leg.ufpr.br/~walmes</a></span><br style="font-family: trebuchet ms,sans-serif;"><span style="font-family: trebuchet ms,sans-serif;">linux user number: 531218</span><br style="font-family: trebuchet ms,sans-serif;">
<span style="font-family: trebuchet ms,sans-serif;">==========================================================================</span><br>