So I've been working off this R script for the last year, but I didn't write it and I need to add an extra group to a graph. Before I added the L1 Spanish group this plot printed beautifully [see the
Old graph]. But now I just get the error of 
"Error in barplot.default(coh, ylim = c(0, 100), ylab = c("% Source"), : 'height' must be a vector or a matrix"
A sample of the data:
L1          SCond   isSource    aspectNames
L1 Spanish  I       1           Imperfective
L1 Spanish  I       1           Imperfective
L1 Spanish  P       0           Perfective
L1 Spanish  P       0           Perfective
L1 Spanish  I       0           Imperfective
L1 Spanish  I       0           Imperfective
English     P       1           Perfective
English     I       1           Imperfective
English     I       1           Imperfective
English     P       1           Perfective
English     P       1           Perfective
English     I       1           Imperfective
L2 Spanish  P       1           Perfective
L2 Spanish  P       0           Perfective
L2 Spanish  P       0           Perfective
L2 Spanish  I       0           Imperfective
L2 Spanish  I       1           Imperfective
L2 Spanish  P       1           Perfective
Japanese    I       1           Imperfective
Japanese    I       1           Imperfective
Japanese    P       1           Perfective
Japanese    P       1           Perfective
Japanese    P       1           Perfective
Japanese    P       1           Perfective
The only changes I made to the following code from the original is adding L1 Spanish and text(2.3,-40, "Error bars +/- 1 SE")
dat <- subset(dat, SCRF != "A")
dat$isSource <- ifelse(dat$SCRF=="S", 1, 0) 
tapply(dat$isSource, list(dat$SCond, dat$L1), mean)
tapply(dat$isSource, list(dat$SCond), mean)
tapply(dat$isSource, list(dat$L1), mean)
coh <- rbind()
coh.ses <- rbind()
for(g in levels(dat$L1)){
    w <- subset(dat, L1==g)
    w.subj <- 100*tapply(w$isSource, list(w$SCond, w$ID), mean)
    mean.subj <- apply(w.subj, 1, mean, na.rm=TRUE)
    # calculate the standard deviation
    sd.subj <- apply(w.subj, 1, sd, na.rm=TRUE)
    # calculate the lengths (number subjects)
    ns.subj <- apply(w.subj, 1, numSubjs)
    # calculate the standard errors
    ses <- sd.subj/sqrt(ns.subj)
    print(mean.subj)
    coh <- cbind(coh,mean.subj)
    coh.ses <- cbind(coh.ses, ses)
}
par(mar = c(4, 4, 0, 2)+2)
bottom = paste("Language group")
CRnames = c("English", "L1 Spanish","L2 Spanish", "Japanese")
legendText = c("Imperfective", "Perfective")
xs <- barplot(coh, ylim=c(0,100), ylab=c("% Source"), names.arg=CRnames,  
              cex.names=1.7, cex.lab=2, sub=bottom, font=2, 
              font.sub=1,cex.sub=1.7,las=1, 
              legend=F,  beside=T)
legend(3.8, 100, text.width=2, legendText, fill=c("gray35", "gray90"), cex=1)
text(2.3,-40, "Error bars +/- 1 SE")
Any idea what's going on???
