es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Cómo convertir un bucle for a una función en R

Estoy intentando convertir un bucle for en una función para las estadísticas resumidas por grupo basadas en los valores de “país” y “continente”. Cualquier ayuda sería apreciada, muchas gracias de antemano.

biblioteca(gapminder)
biblioteca(purr)
cont <- unique(gapminder$continent) df <- NULL temp <- NULL for(i in 1:(length(cont))) { temp <- gapminder[gapminder$continent == cont[i], ] #df[[i]] <- temp df[[i]] <- temp %>% split(.$continent) %>% map(summary)

}
df

Respuesta esperada

mi.funcion(gapminder, c(“país”, “continente”))

Tags:  , , ,

Answer

  1. Avatar for davy.ai

    {
    cont <- unique(gapminder$continent) df <- NULL temp <- NULL for(i in 1:(length(cont))) { temp <- gapminder[gapminder$continent == cont[i], ] df[[i]] <- temp %>% split(.$continent) %>% map(summary)
    }
    return(df)
    }

    {
    cont <- unique(gapminder$continente) df <- NULL temp <- NULL para(i en 1:(longitud(cont))) { temp <- gapminder[gapminder$continente == cont[i], ] df[[i]] <- temp %>% dividir(.$continente) %>% map(resumen)
    }
    return(df)
    }

Comments are closed.