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
#see below for query specifications | |
getInsights <- function( | |
username = "Insights4R@gmail.com", | |
password = "googleinsights4r", | |
text_query = "'hello world'", | |
date_query = "1/2004 108m", | |
geo_query = "US", | |
search_type= "all", | |
filter_category="none"){ |
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
# load required libraries | |
library(tm) | |
library(ggplot2) | |
library(lsa) | |
# 1. Prepare mock data | |
text <- c("transporting food by cars will cause global warming. so we should go local.", | |
"we should try to convince our parents to stop using cars because it will cause global warming.", | |
"some food, such as mongo, requires a warm weather to grow. so they have to be transported to canada.", | |
"a typical electronic circuit can be built with a battery, a bulb, and a switch.", |
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(rjson) | |
library(RCurl) | |
client_id <- "client id here" | |
client_secret <- "client secret here" | |
redirect_uri <- "https://localhost/oauth2callback" | |
auth_url <- "https://accounts.google.com/o/oauth2/auth" | |
scope <- "https://www.googleapis.com/auth/prediction" | |
api_key <- "api key here" |
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
# Please replace this sample profile ID with that of your own | |
# Google Analytics profile. | |
profile_id <- 123456789 | |
# Please ensure you have all of the following libraries | |
# installed first. | |
library(ganalytics) | |
library(httr) | |
library(XML) | |
library(lubridate) |
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
# script stolen from http://goo.gl/YbQyAQ | |
# install.packages("tm") | |
# install.packages("ggplot2") | |
# install.packages("lsa") | |
# install.packages("scatterplot3d") | |
#install.packages("SnowballC") | |
#if !(require('SnowballC')) then install.packages("SnowballC") | |
library(tm) | |
library(ggplot2) |
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
################################ | |
# Problem: You have a ragged | |
# data frame where species that have not | |
# been seen as a site simply don't have a | |
# line in your data frame. You have a long | |
# data frame, but you want a long data frame | |
# where missing species have proper zeroes | |
# | |
# Solution: a combination of dcast and melt | |
# from the reshape2 package |
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
The regex patterns in this gist are intended only to match web URLs -- http, | |
https, and naked domains like "example.com". For a pattern that attempts to | |
match all URLs, regardless of protocol, see: https://gist.github.com/gruber/249502 | |
# Single-line version: | |
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|s |
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
# script stolen from http://goo.gl/YbQyAQ | |
# install.packages("tm") | |
# install.packages("ggplot2") | |
# install.packages("lsa") | |
# install.packages("scatterplot3d") | |
#install.packages("SnowballC") | |
#if !(require('SnowballC')) then install.packages("SnowballC") | |
library(tm) | |
library(ggplot2) |
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(httr) | |
library(XML) | |
library(selectr) | |
xpath <- function(x) structure(x, class = "xpath") | |
sel <- function(x) xpath(css_to_xpath(x, prefix = "//")) | |
url <- "http://www.boxofficemojo.com/movies/?id=ateam.htm" | |
html <- content(GET(url), "parsed") |
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
# Refer to https://rtweet.info/ |
OlderNewer