Combining data points?

I have a table with multiple data points for a species...
species temp min temp max
salt cedar 0 35
salt cedar -5 20
cheatgrass -24 15
cheatgrass 3 33

I need to combine, summarize, or merge the data so that I only have one column for each species with the overall min and max...
species temp min temp max
salt cedar -5 35
cheatgrass -24 33

I have no idea what function to use and I have only been using rstudio for a couple days.

Your overall strategy is to group the data by species and then use evaluate the min and max separately for each group. This can be done in the following manner:

library(dplyr)
df <- 
  structure(
    list(species = c("salt cedar", "salt cedar", "cheatgrass", "cheatgrass"), 
         temp_min = c(0L, -5L, -24L, 3L), 
         temp_max = c(35L, 20L, 15L, 33L)), 
    .Names = c("species", "temp_min", "temp_max"), 
    class = "data.frame", 
    row.names = c(NA, -4L))

df %>% 
  group_by(species) %>% 
  summarise(temp_min = min(temp_min),
            temp_max = max(temp_max))

You may find the materials at http://r4ds.had.co.nz/transform.html helpful.

6 Likes