Category: Resources

Kieran Healy on Publication Workflow

Duke sociologist Kieran Healy has one of my favorite writeups on publication workflows here. It’s about using RMarkdown and Pandoc for writing and presenting manuscripts.

I’ll be presenting later in the term on using this type of workflow to create APA-compliant PDF and DOCX output.

Nice Tables from R Data Frames

The knitr package provides the kable function, which allows you to export data frames as HTML, markdown, and more. It’s really useful along with some background with LaTeX or HTML/CSS to make nicely formatted tables directly from your R output. The code below should get you started.

(Bonus: a brief look at plyr power!)


#install.packages('knitr')
require(knitr)

#lets use the apropos Number of Breaks in Yarn during Weaving data
data(warpbreaks)

#check it out
summary(warpbreaks)

#Let's get the mean and SD for each level of wool
# at each level of tension.

#install.packages('plyr') # This is a great package
require(plyr)

#Split the data by wool and tension, get mean and sd for each
# and return a data frame.
descriptives<-ddply(.data=warpbreaks,
.variables=c('wool','tension'),
.fun=function(x){
round(c(Mean=mean(x$breaks),SD=sd(x$breaks)),2)
})
descriptives

#The default is markdown, and looks pretty good to copy and
# past into a text file.
kable(descriptives)

myHTMLTable<-kable(descriptives,format='html',output=F) getwd() #what directory will it save into? write(myHTMLTable,file='table.html') #Check out the html, and buff it up if you want! #Further reading: # ?kable # ?plyr # Also, google 'markdown' and 'pandoc'

This is the html output:

wool tension Mean SD
A L 44.56 18.10
A M 24.00 8.66
A H 24.56 10.27
B L 28.22 9.86
B M 28.78 9.43
B H 18.78 4.89

Advanced R Programming

Lots of great links, tutorials, and tips! http://adv-r.had.co.nz/

From the webpage: “This is the in-progress book site for “Advanced R development”. The book is designed primarily for R users who want to improve their programming skills and understanding of the language. It should also be useful for programmers coming to R from other languages, as it explains some of R’s quirks and shows how some parts that seem horrible do have a positive side.”

R Color Chart

Do you want to specify a color that’s a bit fancier than ‘red’ or ‘blue’? Here’s a handy grid of color codes for use when plotting. Now when you want to use violetred4, you only need to type 645. Also included are some instructions for exploring the color functions.

R Data Pre-Processing Script from Thursday (using the combn() function)

Hi all,

On Thursday, I showed an R script for pre-processing data for use with Gephi, a network analysis and visualization tool. I’ve published the script, along with an explanation of it, here.

The script uses the combn() function, which takes a vector of items and creates all pairwise (or three-way, or four-way, etc.) combinations of them. It’s a multifunctional tool to have in one’s toolbox.

Written by Comments Off on R Data Pre-Processing Script from Thursday (using the combn() function) Posted in Resources