-
Notifications
You must be signed in to change notification settings - Fork 26
/
making_change.qmd
52 lines (34 loc) · 1.01 KB
/
making_change.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
title: "Making some changes"
format: html
---
The next version of our project will do 3 changes.
1. Add the following code to the end of your R script.
```r
# 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))
```
2. change the command that plots our data in this file. Change the lines
```r
plot(mydata$xdata,mydata$ydata)
```
to
```r
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.
3. Finally, we will **create another R file** (File -> New File -> R script).
Enter the command:
```r
#Simulate some data
plot(rnorm(100,0,1))
```
And save the file as `myscript_too`
***