Error: "Unexpected Symbol" when defining expression

r

Solution

In algebra, two symbols next to each other (e.g. `0.1` and `x` in `0.1x`) imply they are multiplied. In programming, that assumption is not made and an explicit multiplication operator is needed: `0.1*x`.

Problem

I'm in a statistics and data analysis class that recently started using R. I'm getting an error message and so far I haven't been able to determine exactly what the error is or how to fix it. We were given instructions to plot this function: ``` y=0.1x^4-0.5x^3-x^2+3x-2 ``` The next instruction asks to follow this coding and enter the above function: ``` > x<-seq(-5,5,by=2) > y<- ## enter the function, here > plot(y~x) > lines(y~x) ``` This is what I get when I enter the function in `y`: ``` > x<-seq(-5, 5, by=2) > y<-0.1x^4-0.5x^3-x^2+3x-2 ``` Error: unexpected symbol in "y<-0.1x" Is the unexpected symbol the `x`? I tried removing the decimals in the function to test it out but get the same error message: ``` > y<-x^4-5x^3-x^2+3x-2 ``` Error: unexpected symbol in "y<-x^4-5x" So I'm thinking it's the `x` that is the problem, but how do I fix it? I ran the `x` sequence code with no problem.

Original source

Related problems