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
| require(rgdal) | |
| require(ggplot2) | |
| require(dplyr) | |
| shapefile_prep = function(shape.path, shape.name){ | |
| # shape.path = file path to shapefile (character string) | |
| # shape.name = name of shape file (character string) | |
| # reading in the shapefile | |
| ploygons.shp = readOGR(dsn = shape.path, layer = shape.name) %>% |
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
| # creating an R data frame | |
| sim_data = data.frame(X = rnorm(n = 10), | |
| Y = rnorm(n = 10), | |
| Z = rnorm(n = 10)) | |
| # select column j | |
| sim_data[,1] | |
| # ...or by name | |
| sim_data['X'] |
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
| guess_weight = function(posts){ | |
| # reading in the guesses | |
| guesses = readLines(posts) | |
| # Match the guesses in kilograms and store result in vector | |
| kgmatch = regmatches(guesses,regexpr('[1-9]+\\.?[0-9]* *(k|K) *(g|G)(s|S)?',guesses)) | |
| # Changing to numeric and storing in a vector | |
| kgnumerics = as.numeric(regmatches(kgmatch,regexpr('[1-9]+\\.?[0-9]*',kgmatch))) |
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
| # required libraries | |
| library(dplyr) | |
| # loading the iris data set | |
| df.iris = iris | |
| # examining column classes | |
| sapply(X = df.iris, function(X) class(X)) | |
| # the 'base' way |
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
| sqlSave(channel | |
| , dat | |
| , tablename = NULL | |
| , append = FALSE | |
| , rownames = TRUE | |
| , colnames = FALSE | |
| , verbose = FALSE | |
| , safer = TRUE | |
| , addPK = FALSE | |
| , fast = TRUE |
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
| sqlSave(channel, | |
| dat, | |
| tablename = NULL, | |
| append = FALSE, | |
| rownames = TRUE, | |
| colnames = FALSE, | |
| verbose = FALSE, | |
| safer = TRUE, | |
| addPK = FALSE, | |
| fast = TRUE, |
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
| # creating set x | |
| x = set([1,2,3,4,5,6]) | |
| # creating set y | |
| y = set([4,5,6,7,8,9]) | |
| # x UNION y | |
| x.union(y) | |
| {1, 2, 3, 4, 5, 6, 7, 8, 9} |
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
| # required package | |
| library(VennDiagram) | |
| # plot venn | |
| draw.pairwise.venn(area1 = 6, area2 = 6, cross.area = 3, | |
| category = c('x', 'y'), | |
| fill = c('darkred', 'darkgreen'), | |
| alpha = rep(0.3, 2), | |
| scaled = FALSE) |
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
| ################################################# | |
| # un-parameterised | |
| require(dplyr) | |
| df = iris[,sapply(X = iris | |
| , function(X) is.numeric(X))] | |
| df.cluster = df %>% kmeans(x = . |
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
| # required packages | |
| require(dplyr) | |
| require(dygraphs) | |
| require(readxl) | |
| require(stringr) | |
| require(lubridate) | |
| require(xts) | |
| # reading in the data |
OlderNewer