1 Introduction

Walkthrough of how to go from data on invidiual observations to aggregated and summarized data.

Functions Use

2 Load the raw data

dat <- read.csv("miller_real_data_update.csv" )

3 Fix some things

3.1 Remove extra spaces

dat$species<- gsub("^ ","",dat$species)
dat$species<- gsub(" $","",dat$species)

4 Load reshape package

This is what does the magic


4.1 “Melt”" the data

dat$i <- 1:dim(dat)[1]

dat.melt <- melt(data = dat,
     id.vars =c("i","wetland","section","species"),
     measure.vars = c("wet","dry"),
     variable.name = "sample.type")

names(dat.melt)[6] <- "mass"

4.2 “cast” the data

This sums up the total mass for each species. First step done!

dat2 <- dcast(data = dat.melt,
              formula = wetland + section +     
              species ~ sample.type,
              value.var = "mass",
              fun.aggregate = sum)

4.3 Load species list

Load the list of species with what type of plant it is (wetland, uplad etc)

spp.list <- read.csv("species_list_update.csv" )

names(dat2)[3] <- "spp"

4.4 Merge summarized data w/species list

This categorizes each species in the data appropriatly based on what is in the species list

dat3 <- merge(dat2, spp.list, by = "spp")

4.5 Final step: total up within each category of wetland

dat4 <- dcast(data = dat3,
      formula = wetland + section ~ type,
      value.var = "dry",
      fun.aggregate = sum)

and save it

write.csv(dat4, file = "summarized_data.csv")