ComenzarEmpieza gratis

Arguments

Lily and Tom are having an argument because they want to share a hot dog but they can't seem to agree on which one to choose. After some time, they simply decide that they will have one each. Lily wants to have the one with the fewest calories while Tom wants to have the one with the most sodium.

Next to calories and sodium, the hotdogs have one more variable: type. This can be one of three things: Beef, Meat, or Poultry, so a categorical variable: a factor is fine.

Este ejercicio forma parte del curso

Importing Data in R (Part 1)

Ver curso

Instrucciones del ejercicio

  • Finish the read.delim() call to import the data in "hotdogs.txt". It's a tab-delimited file without names in the first row.
  • The code that selects the observation with the lowest calorie count and stores it in the variable lily is already available. It uses the function which.min(), that returns the index the smallest value in a vector.
  • Do a similar thing for Tom: select the observation with the most sodium and store it in tom. Use which.max() this time.
  • Finally, print both the observations lily and tom.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Finish the read.delim() call
hotdogs <- read.delim("hotdogs.txt", header = ___, col.names = c("type", "calories", ___))

# Select the hot dog with the least calories: lily
lily <- hotdogs[which.min(hotdogs$calories), ]

# Select the observation with the most sodium: tom


# Print lily and tom

Editar y ejecutar código