Created
June 12, 2013 17:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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