Data: milk

Skibiel et al 2013. Journal of Animal Ecology. The evolution of the nutrient composition of mammalian milks.


The milk dataset

Data prep

Load data

See script for cleaning info

#Original Table S1 and S2 merged by hand

#set wd()

# Load merged data 
milk <-read.csv("./milk.csv",stringsAsFactors = FALSE, 
                na.strings = c("NA"))

# Get rid of spaces between each row
milk <-na.omit(milk)

# Save temp file
write.csv(milk, "milk_temp.csv",row.names = F)

#reload
milk <- read.csv("milk_temp.csv",
                 stringsAsFactors = FALSE, 
                 na.strings = c("NA","-",""))


Clean data

  • need to clean up some letters used as annotations in the original data
# Remove "*" from fat
milk$fat <- gsub("\\*","",milk$fat)
milk$fat <- as.numeric(milk$fat)


#remove letters from gestation month
milk$gestation.month <-   gsub("[a-zA-Z ]","",milk$gestation.month)
milk$gestation.month <-   gsub("[ ]","",milk$gestation.month)

milk$gest.month.NUM <- as.numeric(milk$gestation.month)





milk$lacatation.months <-   gsub("[a-zA-Z ]","",milk$lacatation.months)

milk$lacatation.months[which(milk$lacatation.months == "7:00")] <- 7

milk$lacat.mo.NUM <- as.numeric(milk$lacatation.months)



milk$mass.litter <-   gsub("[,a-zA-Z ]","",milk$mass.litter)
milk$mass.litter <- as.numeric(milk$mass.litter)

#"Reproductive output was estimated by dividing total litter #mass by maternal mass. Total litter mass was calculated by #multiplying neonate mass by litter size."

milk$diet <- factor(milk$diet)



milk$biome <- gsub(" ","",milk$biome)
summary(factor(milk$biome ))
##     aquatic terrestrial 
##          22         108
milk$biome <- factor(milk$biome)

milk$arid <- factor(milk$arid)


milk$family <- factor(milk$family)
milk$order <- factor(milk$order)
milk$spp <- factor(milk$spp)

Save focal data

write.csv(milk, file = "Skibiel_clean_milk.csv",row.names = F)


Subset focal columns to use

Focal columns

cols.use <- c("order",
              "family",
              "spp",
              "mass.female",
"gest.month.NUM",
"lacat.mo.NUM",
"mass.litter",
"repro.output",
"dev.stage.at.birth",
"diet",
"arid",
"biome",
"fat")


Subset data

Use column indexing by column name

milk2 <- milk[,cols.use]

Change column names to “fat.percent”

i.x <- which(names(milk2) == "fat")
names(milk2)[i.x] <- "fat.percent"

Save data subset

write.csv(milk2,file = "Skibiel_clean_milk_focal_column.csv",row.names = F )