Quiero hacer lo siguiente con un bucle:
ana_1 = data.frame(col1=c(1,2,3,4,5,6,7),
col2=c("rojo","verde","amarillo","amarillo 23","pepe","marta","lento"),
col3=c(150,250,50,100,300,125,200))
ana_2 = data.frame(col1=c(1,2,3,4,5,6,7),
col2=c("rojo","verde","amarillo","amarillo 23","pepe","marta","lento"),
col3=c(150,250,50,100,300,125,200))
ana_3 = data.frame(col1=c(1,2,3,4,5,6,7),
col2=c("rojo","verde","amarillo","amarillo 23","pepe","marta","lento"),
col3=c(150,250,50,100,300,125,200))
pepe_1 = data.frame(col1=c(1,2,3,4,5,6,7),
col2=c("rojo","verde","amarillo","amarillo 23","pepe","marta","lento"),
col3=c(1500,2500,500,1000,3000,1025,2000))
pepe_2 = data.frame(col1=c(1,2,3,4,5,6,7),
col2=c("rojo","verde","amarillo","amarillo 23","pepe","marta","lento"),
col3=c(150,250,50,100,300,125,200))
pepe_3 = data.frame(col1=c(1,2,3,4,5,6,7),
col2=c("rojo","verde","amarillo","amarillo 23","pepe","marta","lento"),
col3=c(150,250,50,100,300,125,200))
resultado <- list()
resultado[["pepe"]] <- pepe_1$col3 + pepe_2$col3 + pepe_3$col3
resultado[["ana"]] <- ana_1$col3 + ana_2$col3 + ana_3$col3
Sumar la col3 de "ana" y meterla en una lista y lo propio con "pepe".
Lo mismo con un bucle, pero no consigo meter el resultado en la lista.
resultado <- list()
sumaprueba <- function(nombre){
df1 <- get(paste0(nombre, "_1"))
df2 <- get(paste0(nombre, "_2"))
df3 <- get(paste0(nombre, "_3"))
resultado[[nombre]] <- df1$col3 + df2$col3 + df3$col3
}
nombres <- c("pepe","ana")
for( i in nombres)
sumaprueba(i)