R version 2.5.0 (2007-04-23) Copyright (C) 2007 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. Error in options(device = x11) : object "x11" not found > sampDat <- read.csv(file="http://www.nd.edu/~steve/Rcourse/hmwrkData/sampleDataFrame.csv") > sampDat[1:2, 1:3] X R1 R2 1 S1 B C 2 S2 A A > > > > help.start() Making links in per-session dir ... If '/usr/bin/open' is already running, it is *not* restarted, and you must switch to its window. Otherwise, be patient ... > subQuant <- function(x) {} > subQuant <- function(x) { + q1 <- quantile(x, .25) + q3 <- quantile(x,.75) + y <- x[x >= q1 & x <= q3] + y } > x1 <- rnorm(10) > summary(x1) Min. 1st Qu. Median Mean 3rd Qu. -0.4916 -0.4213 0.2179 0.2588 0.7741 Max. 1.7500 > class(summary(x1)) [1] "table" > summary(x1)[2] 1st Qu. -0.4213 > countChar <- function(a,s) { + mat <- a[a==s] + length(mat) + } > rownames(sampDat) <- sampDat[,1] > sampDat[ 1:3, 1:3] X R1 R2 S1 S1 B C S2 S2 A A S3 S3 C C > sampDat1 <- sampDat[ ,-1] > sampDat1[1:3, 1:3] R1 R2 R3 S1 B C C S2 A A A S3 C C A > dim(sampDat1) [1] 60 50 > numB <- integer(60) > names(numB) <- rownames(sampDat1) > for( i in 1:60) { + numB[i] <- countChar(sampDat1[i,], "B") + } > numB[1:6] S1 S2 S3 S4 S5 S6 14 7 6 6 7 10 > numB1 <- unlist(lapply(1:60, function(x) { + countChar(sampDat1[x,], "B") })) > numB1[1:6] [1] 14 7 6 6 7 10 >