<html><body><div style="color:#000; background-color:#fff; font-family:lucida console, sans-serif;font-size:12pt">Allan, um CMR é o que nossos amigos precisam para te ajudar.<br><br>Poderia postar o teu banco em um site tipo dropbox, datafile host e enviar o link no email para consulta.<br><br>De qualquer forma, talvez você possa usar a rotina abaixo:Examples<br><br>#AGGREGATE<br>No R<br>?aggregate<br>
<pre>## Compute the averages for the variables in 'state.x77', grouped
## according to the region (Northeast, South, North Central, West) that
## each state belongs to.
aggregate(state.x77, list(Region = state.region), mean)
## Compute the averages according to region and the occurrence of more
## than 130 days of frost.
aggregate(state.x77,
list(Region = state.region,
Cold = state.x77[,"Frost"] > 130),
mean)
## (Note that no state in 'South' is THAT cold.)
## example with character variables and NAs
testDF <- data.frame(v1 = c(1,3,5,7,8,3,5,NA,4,5,7,9),
v2 = c(11,33,55,77,88,33,55,NA,44,55,77,99) )
by1 <- c("red","blue",1,2,NA,"big",1,2,"red",1,NA,12)
by2 <- c("wet","dry",99,95,NA,"damp",95,99,"red",99,NA,NA)
aggregate(x = testDF, by = list(by1, by2), FUN = "mean")
# and if you want to treat NAs as a group
fby1 <- factor(by1, exclude = "")
fby2 <- factor(by2, exclude = "")
aggregate(x = testDF, by = list(fby1, fby2), FUN = "mean")
## Formulas, one ~ one, one ~ many, many ~ one, and many ~ many:
aggregate(weight ~ feed, data = chickwts, mean)
aggregate(breaks ~ wool + tension, data = warpbreaks, mean)
aggregate(cbind(Ozone, Temp) ~ Month, data = airquality, mean)
aggregate(cbind(ncases, ncontrols) ~ alcgp + tobgp, data = esoph, sum)
## Dot notation:
aggregate(. ~ Species, data = iris, mean)
aggregate(len ~ ., data = ToothGrowth, mean)
## Often followed by xtabs():
ag <- aggregate(len ~ ., data = ToothGrowth, mean)
xtabs(len ~ ., data = ag)
## Compute the average annual approval ratings for American presidents.
aggregate(presidents, nfrequency = 1, FUN = mean)
## Give the summer less weight.
aggregate(presidents, nfrequency = 1,
FUN = weighted.mean, w = c(1, 1, 0.5, 1))
</pre>Outra rotina:<br>No R <br>?apply<br>#APPLY<br><pre>## Compute row and column sums for a matrix:
x <- cbind(x1 = 3, x2 = c(4:1, 2:5))
dimnames(x)[[1]] <- letters[1:8]
apply(x, 2, mean, trim = .2)
col.sums <- apply(x, 2, sum)
row.sums <- apply(x, 1, sum)
rbind(cbind(x, Rtot = row.sums), Ctot = c(col.sums, sum(col.sums)))
stopifnot( apply(x, 2, is.vector))
## Sort the columns of a matrix
apply(x, 2, sort)
##- function with extra args:
cave <- function(x, c1, c2) c(mean(x[c1]), mean(x[c2]))
apply(x,1, cave, c1="x1", c2=c("x1","x2"))
ma <- matrix(c(1:4, 1, 6:8), nrow = 2)
ma
apply(ma, 1, table) #--> a list of length 2
apply(ma, 1, stats::quantile)# 5 x n matrix with rownames
stopifnot(dim(ma) == dim(apply(ma, 1:2, sum)))
## Example with different lengths for each call
z <- array(1:24, dim=2:4)
zseq <- apply(z, 1:2, function(x) seq_len(max(x)))
zseq ## a 2 x 3 matrix
typeof(zseq) ## list
dim(zseq) ## 2 3
zseq[1,]
apply(z, 3, function(x) seq_len(max(x)))
# a list without a dim attribute</pre><br><div><span><br></span></div><div> </div><div>Edson Lira<br>Estatístico<br>Manaus-Amazonas<br></div> <div style="font-family: lucida console, sans-serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <hr size="1"> <font face="Arial" size="2"> <b><span style="font-weight:bold;">De:</span></b> "alanarocha@sapo.pt" <alanarocha@sapo.pt><br> <b><span style="font-weight: bold;">Para:</span></b> r-br <r-br@listas.c3sl.ufpr.br> <br> <b><span style="font-weight: bold;">Enviadas:</span></b> Terça-feira, 2 de Julho de 2013 7:41<br> <b><span style="font-weight: bold;">Assunto:</span></b> [R-br] trabalhar com médias<br> </font> </div> <div class="y_msg_container"><br><br>Olá,<br>eu tenho estes dados de 4 grupos:<br>A. pthi <150 B. pthi
150-300 C. pthi 300-600 D. >600<br>112 277 317 1153<br>126 208 454 1199<br> 210 475 2794<br> 257 444 2081<br> 246 493 1576<br> 264 599 901<br> 589 871<br> 583 722<br> 599 1110<br> 548 1412<br> 454 732<br> 382
601<br> 533 1130<br> 335 642<br> 598 682<br> 448 1035<br> 355 1203<br> 462 1136<br> 500 1109<br> 354 805<br> 369 912<br> 547 1454<br> 842<br> 2384<br> 760<br>
675<br> 810<br> 1215<br> 1565<br> 1585<br> 942<br> 827<br> 1015<br> 631<br> 647<br> 709<br> 2192<br> 1392<br> 1028<br> 1201<br>
892<br> 1287<br> 1579<br> 1071<br> 669<br> 1103<br> 964<br> 926<br> 1501<br> 979<br> 1178<br> 625<br> 678<br> 1054<br> 855<br>
983<br> 1076<br> 876<br><br><br>que codigos eu posso fazer no R para responder a estas perguntas:<br>7. Obter a Dose média em cada grupo e o gráfico da sua evolução ao longo do tempo.<br>Ana<br><br>_______________________________________________<br>R-br mailing list<br><a ymailto="mailto:R-br@listas.c3sl.ufpr.br" href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a><br><a href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br" target="_blank">https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br</a><br>Leia o guia de postagem (<a href="http://www.leg.ufpr.br/r-br-guia" target="_blank">http://www.leg.ufpr.br/r-br-guia</a>) e forneça código mínimo reproduzível.<br><br><br></div> </div> </div> </div></body></html>