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
#################################################### | |
# case of global assignment | |
# parent environment is the global environment | |
# from Hadley Wickham's 'Advanced R' | |
##################################################### | |
x <- 0 | |
f <- function() { | |
x <<- 1 | |
} |
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
##################### Import Libraries ############################################## | |
# if you don't have the libraries below you can install the library using the | |
# following command : install.packages('package_name_here_in_quotes') | |
library(dplyr) | |
library(lubridate) | |
library(RColorBrewer) | |
library(leaflet) | |
library(stringr) | |
library(rgdal) |
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
s = ['c' ,'is', 'equal', 'to', 'b'] | |
print(s) | |
# output >> ['c', 'is', 'equal', 'to', 'b'] | |
# dictionary of names:values | |
d = {'joe':['a', 'b'], 'tom':['c', 'd']} | |
# replace any values from the dict with the key value | |
for i in range(0, len(s)): | |
for key,value in d.items(): | |
for v in value: |
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
# code for streaming twitter to a mysql db | |
# for Python 3 and will support emoji characters (utf8mb4) | |
# based on the Python 2 code | |
# supplied by http://pythonprogramming.net/twitter-api-streaming-tweets-python-tutorial/ | |
# for further information on how to use python 3, twitter's api, and | |
# mysql together visit: http://miningthedetails.com/blog/python/TwitterStreamsPythonMySQL/ | |
from tweepy import Stream | |
from tweepy import OAuthHandler |
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
# the following script will import Philadelphia Crime Data | |
# Parts I and II, create a summary based on year, month, and crime type | |
# and will create a basic map in leaflet using the first 1000 incidents | |
# you will need to install dplyr, leaflet, readr, lubridate, and stringr | |
# packages ( install.packages('package name') ) | |
rm(list = ls()) | |
library(dplyr) | |
library(leaflet) | |
library(readr) |
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
(?<!@|#)\b\w+ : Remove all words starting with @ or # (remove hashtags and user handles from twitter) | |
(?<!@|#)\b\w{2,} : Same as above but only keep words with length of 2 or greater |
NewerOlder