Making some changes
The next version of our project will do 3 changes.
- Add the following code to the end of your R script.
# some guesses for the parameters.
= 1
p1 = 0.2
p2
# do the fit
= nls(ydata ~ p1*cos(p2*xdata) + p2*sin(p1*xdata), data = mydata, start = list(p1=p1,p2=p2))
fit
#Plot the fitted line
= data.frame(xdata = seq(min(mydata$xdata),max(mydata$xdata),len=200))
new lines(new$xdata,predict(fit,newdata=new))
- 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.
- 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