Hi good R folks, I am hoping that you could help me resolve this issue. I tried finding answers online but to no avail. I keep getting this "Error in x^2 : non-numeric argument to binary operator" using multiple different codes, ones which have been verified to work by my professor and other students. I tried reinstalling R completely and it still didn't fix the issue. I am using the latest version and Mac 10.8.2. Thank you! I am posting the code where the error occurred below: library(foreign) library(lmtest) library(car) x.1 <- runif(1000,0,1) x.2 <- rbinom(1000,1,.5) b.1 <- 10 b.2 <- 2 mu <- 1+(x.1*b.1) + (x.2*b.2) Z <- cbind(x.1) gamma <- 10 sigma2 <- exp(2+Z*gamma) y <- mu +rnorm(1000) * sqrt(sigma2) lm.y<-lm(y~x.1+x.2) "Error in x^2 : non-numeric argument to binary operator" summary(lm.y) -- View this message in context: http://r.789695.n4.nabble.com/Constant-Error-in-R-tp4645630.html Sent from the R help mailing list archive at Nabble.com.
On Oct 9, 2012, at 2:30 PM, bobo wrote:> Hi good R folks, > > I am hoping that you could help me resolve this issue. I tried finding > answers online but to no avail. > > I keep getting this "Error in x^2 : non-numeric argument to binary operator" > using multiple different codes, ones which have been verified to work by my > professor and other students. > > I tried reinstalling R completely and it still didn't fix the issue. > > I am using the latest version and Mac 10.8.2. > > Thank you! > > I am posting the code where the error occurred below: > > library(foreign) > library(lmtest) > library(car) > > x.1 <- runif(1000,0,1) > > x.2 <- rbinom(1000,1,.5) > > b.1 <- 10 > b.2 <- 2 > > mu <- 1+(x.1*b.1) + (x.2*b.2) > > Z <- cbind(x.1) > > gamma <- 10 > > sigma2 <- exp(2+Z*gamma) > > y <- mu +rnorm(1000) * sqrt(sigma2) > > lm.y<-lm(y~x.1+x.2) > > "Error in x^2 : non-numeric argument to binary operator"Well, something is strange here. Your error message is stating that the interpreter was unable to find x^2, but you have no x^2 expression in your code. I ran the code (except for the library calls which were clearly not needed for those commands. No error. I then loaded the packages and re-ran the code. Again, no errors.> > summary(lm.y)You probably need to restart R with the --vanilla option or if you are using a GUI, locate and rename the .Rdata file and then restart. If the error persist, you should post sessionInfo() results. -- David Winsemius, MD Alameda, CA, USA
> I keep getting this "Error in x^2 : non-numeric argument to > binary operator" > using multiple different codes, ones which have been verified > to work by my professor and other students.I confirm the previous poster's lack of error in running the code supplied. I also agree that something strange is going on. But the error message says you have a non-numeric argument in a binary operator. That means that i) you are using a binary operator (^ in this case) either yourself or in a function you;re calling and ii) either x or 2 is non-numeric. Two possibilities that are siompler than recompiling: First, are you calling the lm() you think you are? Run traceback() after the error to see where it actually occurred. You may find a user-defined function that is masking lm(). That could hang around from a previous R session if you defined one and saved the image on closing. Second: Check the class of your input data. Then fix whichever variable should be numeric and isn't. (this is less likely as lm() returns a different error with non-numeric input). S ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}