SOLUTION TO HW SET 1, presented to illustrate Splus coding style. (This log of Splus commands was generated and tested in Splus3.4) ================================================================= ### Part (a). I put the following statement into my .First function: > attach("/usr/local/StatData/SplusCrs/.Data") > typvec <- unlist(lapply(exampfram,is.numeric)) > tempstuff <- list(minmax = t(apply(exampfram[,typvec],2,range)), labvec= names(exampfram), typvec=c(typvec)) ### Part (b) > cbind.data.frame(exampfram[1:6,1:8], labels=tempstuff$labvec[1:6], TFvals= as.numeric(typvec[7:12])) ### Part (c) > check0 <- data.matrix(exampfram[1:8,typvec]) ## without data.matrix, this is a smaller data-frame, ### not a matrix. In either case, it has a names attribute ### which coincides with the column-name vector ### dimnames(check0)[[2]] or dimnames(exampfram)[[2]][typvec] > checker <- rbind(check0[seq(1,7,2),seq(1,7,2)],check0[2*(1:4), 2*(1:4)])[c(1,5,2,6,3,7,4,8),] ### Part (d) > FrstMn function(dframnam) { typ <- unlist(lapply(dframnam, is.numeric)) apply(dframnam[, typ], 2, mean) } > FrstMn2(exampfram) OBS IDNUM DTH EVTTIME LOGBILI AGEVAR ALBUMIN AUX 108.5 120.6157 0.4768519 47.14347 1.540465 53.20872 34.46435 3.945798 > FrstMn2(LTdata) Stratum Last10. Cellct 16.5 231886.1 2873357 ## Part (e) > Mmat <- matrix(sample(1:150,10000, replace=T), ncol=10) > newlist <- NULL > for(i in 1:10) { tmptab <- table(Mmat[,i]) newlist <- c(newlist,list( matrix(c(as.numeric(names(tmptab)),tmptab), ncol=2, dimnames=list(NULL,c("Values","Freqs"))))) } > length(newlist) [1] 10 > names(newlist) <- paste("Table",as.character(1:10),sep="") > names(newlist) [1] "Table1" "Table2" "Table3" "Table4" "Table5" "Table6" "Table7" [8] "Table8" "Table9" "Table10" > newlist$Table3[1:8,] Values Freqs [1,] 1 11 [2,] 2 2 [3,] 3 8 [4,] 4 6 [5,] 5 8 [6,] 6 10 [7,] 7 6 [8,] 8 6