Spirals and trigonometric functions: R exercise #9

[This article was first published on R programming tutorials and exercises for data science and mathematics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Define a one-line R function FUN that provides the following output:

FUN(seq(from = 0, to = 20, by = 0.1))

FUN(seq(from = 0, to = 100, by = 0.1))

FUN(seq(from = 0, to = 200, by = 0.1))

Answer: click to reveal

We can write the function as follows:

  FUN <- function(x) plot(cbind(x * sin(x), x * cos(x)), type = "l", panel.first = grid(), ann = FALSE, col = "red")

This definition uses the functions cos and sin to plot a spiral with the origin at 0 and also adds grid lines consistent with the axis ticks:

  FUN(seq(from = 0, to = 20, by = 0.1))

For the full collection of R programming tutorials and exercises visit my website at codertime.org and share your comments at .

To leave a comment for the author, please follow the link and comment on their blog: R programming tutorials and exercises for data science and mathematics.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)