Skip to content

Instantly share code, notes, and snippets.

@PirateGrunt
Created June 12, 2013 17:56
Show Gist options
  • Save PirateGrunt/5767596 to your computer and use it in GitHub Desktop.
Save PirateGrunt/5767596 to your computer and use it in GitHub Desktop.
Example of how the dollar sign reference in a dataframe doesn't require the whole name.
myData = data.frame(State = c("NY","NY", "TX", "TX")
, Premium = c(100,200,150,75)
, Loss = c(80,175,80,80))
myData
moreData = data.frame(Premium = myData$P, Loss = myData$L)
moreData
rm(moreData)
colNames = c("Premium", "Loss")
moreData = myData[,colNames]
moreData
rm(moreData)
library(doBy)
totalDf = summaryBy(Premium + Loss ~ State, data = myData, FUN=sum)
totalDf
moreData = data.frame(Premium = totalDf$P, Loss = totalDf$L)
moreData
rm(moreData)
colNames = c("Premium", "Loss")
moreData = totalDf[,colNames]
moreData
rm(moreData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment