Computer Scientist, Graduate Student, and Geek

Category: Uncategorized

Replacing Values in a Vector with NA in R

October 01, 2012

# Load data files
dataA <- read.table("dataA.csv", header=TRUE, sep=",")

# Replace zeros in column ColA with NA
dataA$ColA <- replace(dataA$ColA, data$ColA == 0, NA)

Categories: Uncategorized

Tags: R


Simple CDF Graph in R

August 10, 2012

Below is a sample script for R for creating a cumulative distribution frequency (CDF) graph with one or more curves.

# Load data files
dataA <- read.table("dataA.csv", header=TRUE, sep=",")

# Create CDF points
count <- length(dataA$ColA)-1
cdf.dataA <- data.frame(x=sort(dataA$ColA), y=c(0:count)/count)

# Setup graph parameters
xrange <- c(0, 10)
yrange <- c(0,1)
colors <- c('black') # 'gray39', 'gray69'
linelabels <- c('DataA')
linetype <-c (1)

# Setup output
postscript("cdf.ps", width=5, height=4)
#png("cdf.png", width=400, height=300)

# Setup basic plot
plot(xrange, yrange, type='n', main='', xlab='ColA', ylab='CDF')

# Add lines to plot
lines(cdf.dataA$x, cdf.dataA$y, type='l', col=colors[1], lwd=2,
    lty=linetype[1])

# Add legend
legend(xrange[1], yrange[2], col=colors, lwd=2, lty=linetype,
    legend=linelabels)

# End output
dev.off()

Categories: Uncategorized

Tags: R


Installing Packages in R

March 07, 2012

You can install packages in R by running the following command within R:

install.packages(c("pkg1", "pkg2"))

(See http://cran.r-project.org/doc/manuals/R-admin.html#Installing-packages for more information.)

Categories: Uncategorized

Tags: R


Makefile for ACM Publications in LaTeX

October 18, 2011

Below is the Makefile I use for compiling ACM publications. The LATEX, BIBTEX, PDF, and PS variables should be changed to the absolute paths of latex, bibtex, ps2pdf, and dvips, respectively, if they cannot be found from your PATH environment variable. The variables WORKINGBASE and CAMERABASE should be changed to the name of the main LaTeX file (excluding .tex extension) for your working (i.e., draft) and camera-ready versions, respectively. Use the working (or default) target to compile the working version and the camera target to compile the camera-ready version.

Makefile

LATEX = latex
BIBTEX = bibtex

PDF = ps2pdf
PDF_FLAGS = -dMaxSubsetPct=100 -dCompatibilityLevel=1.2 -dSubsetFonts=true \
-dEmbedAllFonts=true  -dEPSCrop=true

PS = dvips
PS_FLAGS = -P cmz -t letter

WORKINGBASE = main
CAMERABASE = final

default: working

working: version $(WORKINGBASE).pdf

camera: $(CAMERABASE).pdf
    gs -q -dNOPAUSE -dBATCH -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite \
-sOutputFile=$<.tmp $<
    mv $<.tmp $<

version:
    svnversion > version.tex

%.pdf: %.ps
    $(PDF) $(PDF_FLAGS) $< 

.PRECIOUS:%.ps
%.ps: %.dvi
    $(PS) $(PS_FLAGS) $< -o $@

$(WORKINGBASE).dvi: $(wildcard *.tex) $(wildcard *.bib) $(wildcard images/*.eps)
    $(LATEX) ${@:.dvi=}
    $(BIBTEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}

$(CAMERABASE).dvi: $(wildcard *.tex) $(wildcard *.bib) $(wildcard images/*.eps)
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}

clean:
    rm -rRf *.dvi *.aux *.blg *.log *.ps *~ *.bbl *.pdf *.out

I also set the svn:ignore property on the subversion directories in which LaTeX files and Makefile are stored. Run

svn propedit svn:ignore .
and add the following:
*.aux
*.bbl
*.blg
*.log
*.dvi
*.ps
version.tex
main.pdf

(Change main.pdf to whatever is stored in the WORKINGBASE variable in the Makefile, plus the .pdf extension.)

Categories: Uncategorized

Tags: acm, latex


Compiling LaTeX Publications for Conference Proceedings

July 25, 2011

As a computer science graduate student, compiling LaTeX publications for conferences is a frequent task. For the draft and submission versions, compilation settings are not as particular, but a final camera ready version has certain requirements, such as a PDF with embedded fonts. I have built a Makefile that allows me to compile everything from my early drafts to the final camera-ready version that meets the requirements of typical ACM publications.

The Makefile assumes your main LaTeX file is called main.tex (change the value assigned to the BASE variable if yours is different). Also, the camera-ready compilation process assumes you have a single latex file called camera.tex that contains all tex files and the bbl, the compiled bibliography (change the value assigned to the CAMERABASE variable if yours is different).

LATEX = latex
BIBTEX = bibtex

PDF = ps2pdf
PDF_FLAGS = -dPDFSETTINGS=/prepress

PS = dvips
PS_FLAGS = -t letter

BASE = main
CAMERABASE = camera

.PRECIOUS:$(CAMERABASE).ps

all: version $(BASE).pdf

camera: $(CAMERABASE).pdf

version:
    svnversion > version.tex

%.pdf: %.ps
    $(PDF) $(PDF_FLAGS) $< 

%.ps: %.dvi
    $(PS) $(PS_FLAGS) $< -o $@

$(BASE).dvi: $(wildcard *.tex) $(wildcard *.bib) $(wildcard images/*.eps)
    $(LATEX) ${@:.dvi=}
    $(BIBTEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}

$(CAMERABASE).dvi: $(wildcard *.tex) $(wildcard *.bib) $(wildcard images/*.eps)
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}

clean:
    rm -rf *.dvi *.aux *.blg *.log $ *~ *.bbl *.out
    rm -rf (BASE).ps $(BASE).pdf $(CAMERABASE).pdf

Categories: Uncategorized

Tags: latex, subversion


Parse a CSV File Using Awk

July 06, 2011

To perform text processing on a CSV file row-by-row, you can use awk. A single row can be split into columns using the split command. The data can be output as desired using the print command. The example below outputs the 1st and 3rd columns of a CSV file:

cat myfile.csv | awk '{ split($0,a,","); print a[1]","a[3]; }'

It is important to note that awk uses one-based array indexing (not zero-based).

Categories: Uncategorized

Tags: awk


Enable Uploads in MediaWiki

May 02, 2011

To enable uploads (images and PDFs) in MediaWiki, make the following changes to the LocalSettings.php file for the installation:

  1. Change the line
    $wgEnableUploads       = false;
    to
    $wgEnableUploads       = true;
  2. Add the line
    $wgFileExtensions = array_merge($wgFileExtensions, array('pdf'));
    to also allow PDFs to be uploaded.

Categories: Uncategorized

Tags: mediawiki


CS Unplugged

June 25, 2009

CS Unplugged is a series of learning activities designed for elementary, middle, and high school students which teach computer science topics without using a computer. I was first introduced to CS Unplugged at SIGCSE 2008. This week, another computer science student and I did three different activities with teachers which attend a workshop on computational sciences at Marquette University.

Other activities are available online at http://csunplugged.org.

Categories: Uncategorized

Tags: