# This is an Splus command script # written by Ashton Shortridge, April 6, 2000 # First some simple stuff # 1+2 # S-Plus can be a calculator! big <- 45 * 59 # Create an object called big. Assign 45*59 to it. big/20 # Prints result but does not affect value of big smaller <- big/40 # New assignment big <- smaller/55 # Assign a new value to big big <- big / smaller # Splus doesn't choke on this sort of thing. big # prints the new value for big. rm(big) # erase the big object rm(smaller) # erase the smaller object. It's just a little smaller now! # Now some more complicated stuff index <- c(1:50) # Assignment statement. Object (vector) named "index" gets values 1-50 noisy<-rnorm(50,100,50) #Object (vector) "noisy" gets 50 values randomly drawn from a normal distribution with m=100, sd=50 quiet<-rnorm(50,100,10) ntrend_noisy + index # underscore "_" is same as <- qtrend_quiet+index # Splus knows how to add vectors. Spacing not important. t.test(ntrend,qtrend, var.equal=F) # see help on this complex function # You can try to interpret results of the T-test from the output. # You could also write the output as an object by assignment. plot(ntrend) #opens a graphics window and does the plot points(qtrend, pch=3) #add some diff't points to the plot title(main="Noisy vs Quiet data") two.trends_as.data.frame(cbind(ntrend,qtrend)) #This is a compound expression. # cbind creates a matrix object w/ the two vectors # as.data.frame turns the matrix into a data frame rm(index) #erase the index object rm(qtrend,ntrend,quiet,noisy) #erase lots more stuff in one line