Making some changes

The next version of our project will do 3 changes.

  1. Add the following code to the end of your R script.
# some guesses for the parameters.
p1 = 1
p2 = 0.2

# do the fit
fit = nls(ydata ~ p1*cos(p2*xdata) + p2*sin(p1*xdata), data = mydata, start = list(p1=p1,p2=p2))

#Plot the fitted line
new = data.frame(xdata = seq(min(mydata$xdata),max(mydata$xdata),len=200))
lines(new$xdata,predict(fit,newdata=new))
  1. change the command that plots our data in this file. Change the lines
plot(mydata$xdata,mydata$ydata)

to

plot(mydata$xdata,mydata$ydata,col='red')

We do this so we can illustrate how git handles modifications of existing lines as well as simply adding extra lines of code.

Make sure the code runs before proceeding further and save the script.

  1. Finally, we will create another R file (File -> New File -> R script).

Enter the command:

#Simulate some data
plot(rnorm(100,0,1))

And save the file as myscript_too