[R-es] pregunta

Carlos Ortega cof en qualityexcellence.es
Mie Oct 28 00:13:45 CET 2015


Otras variantes con y sin paquetes adicionales...

> sapply(split(datIn$Gain, as.factor(datIn$Diet)), mean)
 d1  d2  d3
280 278 312
> by(datIn$Gain, datIn$Diet, mean)
datIn$Diet: d1
[1] 280
--------------------------------------------------------------
datIn$Diet: d2
[1] 278
--------------------------------------------------------------
datIn$Diet: d3
[1] 312
>
> library(dplyr)
> summarise(group_by(datIn, Diet), mean(Gain))
Source: local data frame [3 x 2]

   Diet mean(Gain)
  (chr)      (dbl)
1    d1        280
2    d2        278
3    d3        312
>
> library(sqldf)
> sqldf("select Diet,avg(Gain) from datIn group by Diet")
  Diet avg(Gain)
1   d1       280
2   d2       278
3   d3       312


Saludos,
Carlos Ortega
www.qualityexcellence.es

2015-10-27 22:45 GMT+01:00 eric <ericconchamunoz en gmail.com>:

> tambien te sirve la funcion data.table ... si no tienes instalado el
> paquete:
>
> install.packages("data.table")
> library(data.table)
> jbe <- as.data.table(read.table("tusdatos.txt"))
> jbe.ave <- jbe[, .("ave"=mean(Gain)), by=.(Diet)]
>
> > jbe.ave
>    Diet ave
> 1:   d1 280
> 2:   d2 278
> 3:   d3 312
>
>
> Saludos.
>
> Eric.
>
>
> On 10/27/2015 05:16 PM, jbetancourt wrote:
>
>>
>> Estimados
>>
>> Cuando existia epicalc,  hab�a una  manera muy f�cil de determinar la
>> media de una variable (en esta caso Gain)  por grupos, en este caso (Diet).
>> ?Como se puede hacer ahora?
>>
>>        Diet Gain
>> 1    d1  270
>> 2    d1  300
>> 3    d1  280
>> 4    d1  280
>> 5    d1  270
>> 6    d2  290
>> 7    d2  250
>> 8    d2  280
>> 9    d2  290
>> 10   d2  280
>> 11   d3  290
>> 12   d3  340
>> 13   d3  330
>> 14   d3  300
>> 15   d3  300
>>
>> Saludos
>> Jos�
>>
>>         [[alternative HTML version deleted]]
>>
>>
>>
>> _______________________________________________
>> R-help-es mailing list
>> R-help-es en r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>>
> --
> Forest Engineer
> Master in Environmental and Natural Resource Economics
> Ph.D. student in Sciences of Natural Resources at La Frontera University
> Member in AguaDeTemu2030, citizen movement for Temuco with green city
> standards for living
>
> Nota: Las tildes se han omitido para asegurar compatibilidad con algunos
> lectores de correo.
>
>
> _______________________________________________
> R-help-es mailing list
> R-help-es en r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

	[[alternative HTML version deleted]]



Más información sobre la lista de distribución R-help-es