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
df <- data.frame( | |
a = rnorm(10), | |
b = rnorm(10), | |
c = rnorm(10), | |
d = rnorm(10) | |
) | |
# Replace the 1:ncol(df) sequence | |
for (i in seq_along(df)) { | |
print(median(df[[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
# Install a package and load it. | |
installRequiredPackages <- function(pkg){ | |
new.pkg <- pkg[!(pkg %in% installed.packages()[,"Package"])] | |
if (length(new.pkg)) | |
install.packages(new.pkg, dependencies = TRUE) | |
sapply(pkg, require, character.only = TRUE) | |
} | |
libs <- c("readr", "dplyr", "tidyr", "ggplot2", | |
"magrittr", "markdown", "knitr", "Hmisc", |
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
# Takes a list of status/twitter objects, extracts the text, | |
# cleans the text, calculates word frequencies and generates | |
# a word cloud. | |
generateWordCloud <- function(tweets){ | |
#Get the text from the status/twitter object | |
tweets_list <- sapply(tweets, function(x) x$getText()) | |
#Remove any weird symbols from the text | |
tweets_list <- str_replace_all(tweets_list, "[^[:graph:]]", " ") |
NewerOlder