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
| var http = require('http'); | |
| var https = require('https'); | |
| var fs = require('fs'); | |
| var post_array = []; | |
| var user_array = []; | |
| fs.writeFile('posts.csv', 'Author,ID,Post Date,Comments,Score,Stickied,Pull,Subreddit\n', function(){console.log('done')}); | |
| fs.writeFile('users.csv', 'Author,Author Date\n', function(){console.log('done')}); | |
| var subreddits = ["AskReddit", "politics", "The_Donald", "funny", "nba", "Overwatch", "gaming", "pics", "news", "todayilearned", "videos", "movies", "worldnews", "soccer", "relationships", "WTF", "SandersForPresident", "AdviceAnimals", "gifs", "leagueoflegends", "aww", "BlackPeopleTwitter", "hockey", "SquaredCircle", "gameofthrones", "nfl", "GlobalOffensive", "h3h3productions", "arrow", "DotA2", "pcmasterrace", "hiphopheads", "me_irl", "Showerthoughts", "science", "Mr_Trump", "Games", "mildlyinteresting", "asoiaf", "technology", "hillaryclinton", "IAmA", "4chan", "hearthstone", "TumblrInAction", "magicTCG", "Jokes", "PoliticalDiscussion", "tifu", "baseball", "CFB", "enoughsanderss |
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
| set.seed(1) | |
| df <- data.frame(x=rnorm(10), y=rnorm(10)) | |
| d1 <- dist(df) | |
| min(d1) | |
| #0.2036045 | |
| which.min(d1) | |
| #43 | |
| df[combn(row.names(df),2)[,match(min(d1),d1)],] | |
| # x y |
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
| #https://www.washingtonpost.com/news/the-fix/wp/2016/09/26/the-first-trump-clinton-presidential-debate-transcript-annotated/ | |
| transcript <- read.csv(file="~/R/reddit/speach/import/transcript.csv",header = FALSE, stringsAsFactors = FALSE) | |
| colnames(transcript) <- c("candidate","statement") | |
| transcript_melted <- matrix(data="NA",nrow = 0,ncol = 2) | |
| for(i in 1:nrow(transcript)) { | |
| #removes non alphanumeric, then splits statement into a vector of words | |
| words <- unlist(strsplit(gsub("[^[:alnum:] \']", "", transcript[i,"statement"]), " ")) | |
| for(word in words) { | |
| transcript_melted <- rbind(transcript_melted, c(transcript[i,"candidate"],word)) | |
| } |
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
| #https://www.washingtonpost.com/news/the-fix/wp/2016/10/09/everything-that-was-said-at-the-second-donald-trump-vs-hillary-clinton-debate-highlighted/ | |
| transcript <- read.csv(file="~/R/reddit/speach/import/transcript-2nd-debate.csv",header = FALSE, stringsAsFactors = FALSE) | |
| colnames(transcript) <- c("candidate","statement") | |
| transcript_melted <- matrix(data="NA",nrow = 0,ncol = 2) | |
| for(i in 1:nrow(transcript)) { | |
| #removes non alphanumeric, then splits statement into a vector of words | |
| words <- unlist(strsplit(gsub("[^[:alnum:] \']", "", transcript[i,"statement"]), " ")) | |
| for(word in words) { | |
| transcript_melted <- rbind(transcript_melted, c(transcript[i,"candidate"],word)) | |
| } |
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
| #https://www.washingtonpost.com/news/the-fix/wp/2016/10/19/the-final-trump-clinton-debate-transcript-annotated/ | |
| transcript <- read.csv(file="~/R/reddit/speach/import/transcript-3rd-debate.csv",header = FALSE, stringsAsFactors = FALSE) | |
| colnames(transcript) <- c("candidate","statement") | |
| transcript_melted <- matrix(data="NA",nrow = 0,ncol = 2) | |
| for(i in 1:nrow(transcript)) { | |
| #removes non alphanumeric, then splits statement into a vector of words | |
| words <- unlist(strsplit(gsub("[^[:alnum:] ]", "", transcript[i,"statement"]), " ")) | |
| for(word in words) { | |
| transcript_melted <- rbind(transcript_melted, c(transcript[i,"candidate"],word)) | |
| } |
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
| var http = require('http'); | |
| var https = require('https'); | |
| var fs = require('fs'); | |
| var post_array = []; | |
| var user_array = []; | |
| fs.writeFile('posts.csv', 'Author,ID,Post Date,Comments,Score,Stickied,Pull,Subreddit\n', function(){console.log('Cleared posts.csv')}); | |
| fs.writeFile('users.csv', 'Author,Author Date\n', function(){console.log('Cleared users.csv')}); | |
| subreddits = ["all"] | |
| for (var i=0;i<subreddits.length; i++) { |
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
| setwd("~/R/Merge Stuff") | |
| install.packages("openxlsx") | |
| library("openxlsx") | |
| file <- list() | |
| #base file is the original you are working from | |
| #update file is the file with new information which updates base cells | |
| #error file contains information in new columns which are appended | |
| file$base <- read.xlsx("base.xlsx") | |
| file$update <- read.xlsx("update.xlsx") |
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
| html.data.frame <- function(table,id="records") { | |
| df <- data.frame(table) | |
| for(i in 1:ncol(df)) { | |
| df[,i] <- as.character(df[,i]) | |
| df[,i] <- gsub("&", "&", df[,i]) | |
| df[,i] <- gsub("<", "<", df[,i]) | |
| df[,i] <- gsub(">", ">", df[,i]) | |
| } | |
| html <- paste0('<table id="',id,'">') | |
| html <- paste0(html,"<thead><tr><td>",paste(names(df),collapse = "</td><td>"),"</td></tr></thead><tbody>") |
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
| termination_words <- toupper(as.character(sapply(unlist(strsplit(text,'\\.')),function(x) { | |
| words <- unlist(strsplit(x,' ')) | |
| return(words[length(words)]) | |
| }))) |
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
| let http = require('http'); | |
| let https = require('https'); | |
| let fs = require('fs'); | |
| let cheerio = require('cheerio') | |
| var letters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']; | |
| fs.writeFile('report.csv', "Name,Grades,County,City,Link\r\n", function(){console.log('done')}); | |
| for(var i=0;i<letters.length;i++) { | |
| scrape(letters[i]); | |
| } |