On Fri, 2005-07-15 at 15:40 -0500, David Groos wrote: > I'm trying to figure out R, a piece at a time, hours at a time... I > was trying to copy the sample function in, "An Introduction to R" (for > version 2.1.0) by W. N. Venables, D. M. Smith, page 42. Section 10.1 > "Simple examples" provides a sample function which I tried to duplicate > (I'm using Mac OS X 10.3.9, and "R for Mac OS X Aqua GUI v1.11). The > following is what I typed and the last line is R's response when I hit > the return key after the penultimate line. I've re-checked and > re-typed the code many times to no avail. I wasn't able to find this > issue using search options, either. Any help is GREATLY appreciated! > > > twosam<-function(y1, y2) { > + n1<-length(y1);n2 <-length(y2) > + yb1<-mean(y1); yb2<-mean(y2) > + s1<-var(y1);s2<-var(y2) > + s<-((n1-1)*s1 + (n2-1)*s2)/(n1+n2-2) > + tst<-(yb1-yb2)/sqrt(s*(1/n1+1/n2)) > Error: syntax error > > David
The code as you have above (without the "+" on each line) works for me both in ESS and in the R console under Linux. There should be another "+" on the next line, in anticipation of the remaining two lines: tst } Try to copy and paste the following into the console as is: twosam<-function(y1, y2) { n1 <- length(y1);n2 <- length(y2) yb1 <- mean(y1); yb2 <- mean(y2) s1 <- var(y1);s2 <- var(y2) s <- ((n1-1)*s1 + (n2-1)*s2)/(n1+n2-2) tst <- (yb1-yb2)/sqrt(s*(1/n1+1/n2)) and see what happens. You should be left at a: + on a new line again. It is possible that there is a bug in the Aqua GUI, but not using a Mac, I cannot replicate it. You might want to consider subscribing and posting to the R-SIG-Mac e-mail list, which is focused on Mac users of R. More information is here: https://stat.ethz.ch/mailman/listinfo/r-sig-mac HTH, Marc Schwartz P.S. Greetings from Eden Prairie ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html