This file contains hidden or 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
| 'Source: Power programming VBA p86-87 | |
| Sub CloseInactive() | |
| Dim Book as Workbook | |
| For Each Book In Workbooks | |
| If Book.Name <> ActiveWorkbook.Name Then Book.Close | |
| Next Book | |
| End Sub |
This file contains hidden or 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
| #create a vector of characters we want to sample from | |
| expl <- c("#","$","@","%","*","!") | |
| #example - sample two characters | |
| #and collapse the characters into one element | |
| samp <- sample(expl,2) | |
| samp2 <- paste(samp,collapse="") | |
| samp2 | |
| #example function |
This file contains hidden or 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
| #create a vector of characters we want to sample from | |
| expl <- c("#","$","@","%","*","!") |
This file contains hidden or 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
| #example - sample two characters | |
| #and collapse the characters into one element | |
| samp <- sample(expl,2) | |
| samp2 <- paste(samp,collapse="") | |
| samp2 |
This file contains hidden or 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
| #example function | |
| expletive <- function(nochars) { | |
| expleti <- paste(sample(expl,nochars),collapse = "") | |
| return(expleti) | |
| } | |
| #assign result of this function to a new variable | |
| cursing <- expletive(5) |
This file contains hidden or 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
| myfunction <- function(arg1, arg2, ... ){ | |
| statements | |
| return(object) | |
| } |
This file contains hidden or 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
| #name.of.function <- function(argument1, argument2) { | |
| # statements | |
| # return(something) | |
| #} | |
| function() |
This file contains hidden or 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
| library(reshape2) | |
| library(dplyr) | |
| #taveras p128 | |
| batting <- read.csv("C:/RFiles/baseball/batting.csv") | |
| names(batting) | |
| # keep stats for 2008 and onward | |
| x = filter(batting, yearID >= 2008) |
This file contains hidden or 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
| 1 + 1 | |
| x <- 2 | |
| #assign the sqrt of 25 to x | |
| x <- sqrt(25) | |
| x | |
| help(sqrt) |
This file contains hidden or 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
| #PIE CHART | |
| ?pie | |
| nycpop <- data.frame(borough = c("Manhattan", "Brooklyn", "Queens", "Bronx", "Staten Island"), | |
| population = c(1.64, 2.63, 2.33, 1.46, .47)) | |
| #create a pie chart | |
| nycpie <- pie(nycpop$population, labels = nycpop$borough) |