Skip to content

Instantly share code, notes, and snippets.

View behaeghe's full-sized avatar

JR Behaeghel behaeghe

View GitHub Profile
@behaeghe
behaeghe / cleanupTwitter
Created October 31, 2017 11:33
Cleaning a twitter feed in R
gsub("rt", "", x) # remove Retweet
gsub("@\\w+", "", x) # remove at(@)
gsub("[[:punct:]]", "", x) # remove punctuation
gsub("[[:digit:]]", "", x) # remove numbers/Digits
gsub("http\\w+", "", x) # remove links http
gsub("[ |\t]{2,}", "", x) # remove tabs
gsub("^ ", "", x) # remove blank spaces at the beginning
gsub(" $", "", x) # remove blank spaces at the end
@behaeghe
behaeghe / readPDF.R
Last active September 25, 2017 12:06
Reading a PDF file using the tm package readPDF function
library(tm)
# File name
filename = "./data/ICHE6.PDF"
# Read the PDF file
doc <- readPDF(control = list(text = "-layout"))(elem = list(uri = filename),language = "en",id = "id1")
# Here's how it works
## ReadPDF returns a function
fun <- readPDF(control = list(text= "-layout"))
## Feigenbaum.R
library(compiler) ## requires R >= 2.13.0
logistic.map <- function(r, x, N, M){
## r: bifurcation parameter, x: initial value
## N: number of iterations, M: iterations to be returned
z <- 1:N
z[1] <- x
for(i in c(1:(N-1))){
z[i+1] <- r *z[i] * (1 - z[i])
}