The following scirits are stolen from one of the stackoverflow anwser to Approximating function with Neural Network
This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
set.seed(1405)
x <- sort(10*runif(50))
y <- sin(x) + 0.2*rnorm(x)
nn <- nnet(x, y, size=6, maxit=40, linout=TRUE)
# weights: 19
initial value 22.620862
iter 10 value 19.387017
iter 20 value 12.562669
iter 30 value 2.542834
iter 40 value 1.196062
final value 1.196062
stopped after 40 iterations
plot(x, y)
plot(sin, 0, 10, add=TRUE)
x1 <- seq(0, 10, by=0.1)
lines(x1, predict(nn, data.frame(x=x1)), col="green")

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
LS0tDQp0aXRsZTogIkFwcHJveGltYXRpbmcgZnVuY3Rpb24gd2l0aCBOZXVyYWwgTmV0d29yayINCm91dHB1dDogaHRtbF9ub3RlYm9vaw0KLS0tDQoNCg0KVGhlIGZvbGxvd2luZyBzY2lyaXRzIGFyZSBzdG9sZW4gZnJvbSBvbmUgb2YgdGhlIHN0YWNrb3ZlcmZsb3cgYW53c2VyIHRvIFtBcHByb3hpbWF0aW5nIGZ1bmN0aW9uIHdpdGggTmV1cmFsIE5ldHdvcmtdKGh0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vcXVlc3Rpb25zLzE1NjUxMTUvYXBwcm94aW1hdGluZy1mdW5jdGlvbi13aXRoLW5ldXJhbC1uZXR3b3JrKQ0KDQpgYGB7ciBzZXR1cCwgaW5jbHVkZT1GQUxTRX0NCmtuaXRyOjpvcHRzX2NodW5rJHNldChlY2hvID0gVFJVRSkNCg0KbGlicmFyeSh0aWR5dmVyc2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