[R-es] Promedio elementos vector

Manuel Máquez manuelmx11 en gmail.com
Jue Ago 17 19:06:45 CEST 2017


Claro que sí.
ko <- matrix(0, 39, 48, byrow = T)        # Matriz p/contar 39 numeros y
max de 48 c/u
ks <- matrix(0, 39, 48, byrow = T)        # Matriz p/sumar
dt <- read.csv('TDist.csv', header = F)   # Tabla de datos
for(i in 1:length(dt$V1)) {
    for(j in 1:39) {
        da <- dt[i, j]
        if(da > 0) {ko[j, da] <- ko[j, da] + 1
        }
    }
}
write.csv(ko, file = 'ContaC.csv')
datIn <- read.table("ContaC.csv", header = TRUE, sep =",", as.is = TRUE)
datIn$X <- NULL
mfun <- function(x) {
    val_sum <- sum(x)
    x_avg <- round(x/val_sum,5)
    return(x_avg)
}
datOut <- apply(datIn, 1, mfun)
datEnd <- as.data.frame(t(datOut))
write.csv(datEnd, file = 'Sali753.csv')
También te adjunto TDist.csv.
Gracias
*MANOLO MÁRQUEZ P.*
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20170817/726ee8c6/attachment-0001.html>
------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: TDist.csv
Type: text/csv
Size: 59648 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20170817/726ee8c6/attachment-0001.csv>


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