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
i <- 1:50 | |
b <- 1:5 | |
ColNames <- paste0("X_", i, "_", rep(b, each=length(i))) |
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
df[, !(colnames(df) %in% c("x","bar","foo"))] |
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
import pandas as pd | |
df = pd.DataFrame([ | |
['2018-03-11', '11:03', 86], | |
['2018-03-14', '09:27', 43], | |
['2018-03-14', '12:08', 22], | |
['2018-03-15', '03:13', 140], | |
['2018-03-17', '18:06', 10]], | |
columns=['Date','Time','Duration']) | |
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
mtcars[, c("cyl", "am", "gear")] <- lapply(mtcars[, c("cyl", "am", "gear")], as.factor) | |
p <- ggplot(mtcars, aes(mpg, wt, group = cyl)) + | |
geom_line(aes(color=cyl)) + | |
geom_point(aes(shape=cyl)) + | |
facet_grid(gear ~ am) + | |
theme_bw() | |
p | |
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
library(tidyr) | |
df <- data.frame( | |
MKT=c("ABIORD", "ABIBOS", "GCFPQR", "ABIORD", "ABIBOS", "GCFPQR", "ABIORD", "ABIBOS", "GCFPQR"), | |
VERSION=c(1,2,3,4,1,2,3,4,1), | |
REVERSALS=c(7,6,7,7,7,6,7,7, 9), | |
NEIGH=c(1,2.3,3.3,4,3.3,2,1,3.3,4.3), | |
DIFFMETRIC=c(1.1,2.1,3.1,4.1,3.1,2.1,1.1,3.1,4.1)) | |
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
def common_elements(list1, list2): | |
return list(set(list1) & set(list2)) | |
import itertools | |
fileidx = 1 | |
for x,y in itertools.combinations(cards, 2): | |
match = common_elements(x, y) | |
print(len(match), match) | |
if len(match): |
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
library(dplyr) | |
df1 <- mtcars | |
df2 <- filter(mtcars, mpg >19) | |
names(df1) | |
col1 <- 'qsec' | |
val1 <- 15.5 | |
col2 <- 'qsec' |
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
mgsub <- function(pattern, replacement, x) { | |
if (length(pattern)!=length(replacement)) { | |
stop("pattern and replacement do not have the same length.") | |
} | |
result <- x | |
for (i in 1:length(pattern)) { | |
result <- gsub(pattern[i], replacement[i], result) | |
} | |
result | |
} |
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
library(ggvis) | |
library(shiny) | |
#Example of Selectize, with Multiple = TRUE | |
ui = shinyUI(pageWithSidebar( | |
div(), | |
sidebarPanel( | |
sliderInput("n", "Number of points", min = 1, max = nrow(mtcars), | |
value = 10, step = 1), |
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
#understanding the code behind Bob Rudis' blog post | |
#https://rud.is/b/2015/05/14/geojson-hexagonal-statebins-in-r/ | |
rm(list=ls()) | |
library(rgdal) | |
library(rgeos) | |
require(maptools) | |
setwd("~/RStats/data") | |
ogrInfo("us_states_hexgrid.geojson", "OGRGeoJSON") |