Skip to content

Instantly share code, notes, and snippets.

@cronin101
Created December 11, 2013 15:28
Show Gist options
  • Select an option

  • Save cronin101/7912393 to your computer and use it in GitHub Desktop.

Select an option

Save cronin101/7912393 to your computer and use it in GitHub Desktop.
Arse Crypt
# Read the CSV file into R
citations <- read.csv("citations2013.csv")
# At this point, people were told to attach(). Apparently that's icky.
print("Dataset contains the following columns:")
print(names(citations))
print("Length of citations$Citations2013:")
print(length(citations$Citations2013))
print("Dataset dimensions:")
print(dim(citations))
print("Summary of the dataset:")
print(summary(citations))
print("Mean number of citations in 2013:")
print(mean(citations$Citations2013, na.rm=T))
print("Standard deviation of citations in 2013:")
print(sd(citations$Citations2013, na.rm=T))
print("Median number of citations in 2013:")
print(median(citations$Citations2013, na.rm=T))
# Generate a histogram of 2013 citation frequency
hist(citations$Citations2013)
# Find which paper is skewing the results, syntax is [row_selector, column_selector]:
print(citations[which.max(citations$Citations2013), ])
# Transform citations to log scale for 2013...
log_scale_2013_citations <- log(citations$Citations2013 + 1)
hist(log_scale_2013_citations, col="gray80")
# ...and 2012
log_scale_2012_citations <- log(citations$Citations2012 + 1)
hist(log_scale_2012_citations, col="lightblue")
# Log/log scale for 2013
log_scale_hist <- hist(log_scale_2013_citations, plot=F)
log_scale_hist$counts = log(log_scale_hist$counts + 1)
plot(log_scale_hist, ylab="Log Frequency")
without_cover = log_scale_2013_citations[citations$Cover.Photo == 0]
with_cover = log_scale_2013_citations[citations$Cover.Photo == 1]
# Side-by-side plot of with and without cover photo
par(mfrow=c(1, 2))
hist(with_cover, breaks=seq(0,8), main=NULL, xlab="Log Citations", col="lightblue")
hist(without_cover, breaks=seq(0,8), main=NULL, xlab="Log Citations", col="pink")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment