官术网_书友最值得收藏!

Setting up a New Project 

Let us now set up a new project that we will use throughout the book. We will create an R project, script, custom function, and save an image of the global environment. Follow the steps given below:

  1. Open RStudio.
  2. Navigate to File | New Project to start a new project:
    • Start with a new directory and save it in a place on your computer that makes sense to you.
    • Save the project with the name IntroToDSwRCourse.
  3. Check the working directory using the getwd() function and be sure it's the same folder you chose to save your project in.
  4. Start a new script. Save the script with the filename lesson1_exercise.R.
  5. Write a custom function, area_rectangle(), which calculates the area of a rectangle, with the following code:
area_rectangle <- function(length, width){
length * width
}
  1. Try out area_rectangle() with the following sets of lengths and widths:
    • 5, 10
    • 80, 7
    • 48209302930, 4

The code will be as follows:

area_rectangle(5, 10)
area_rectangle(80, 70)
area_rectangle(48209302930, 4)
  1. Save an image of the global environment for later; name the file introToDSwR.RData.

Output: The output you get after executing the getwd() function will be the folder on your computer that you have chosen to save your project in.

The area of the rectangle with different lengths will be provided as follows:

R and RStudio will be our main tools throughout this book for statistical analysis and programming. We've now seen how to create a new project, a new R script, and how to save a workspace image for use later.

主站蜘蛛池模板: 台南市| 金昌市| 新郑市| 永宁县| 长兴县| 富川| 来安县| 府谷县| 岑巩县| 恩平市| 壤塘县| 大丰市| 封开县| 同心县| 乌鲁木齐县| 比如县| 远安县| 巩留县| 河曲县| 哈巴河县| 南充市| 昌江| 泽州县| 炉霍县| 苗栗县| 饶阳县| 肃宁县| 宜宾市| 高平市| 新建县| 太谷县| 临桂县| 龙游县| 本溪市| 昌吉市| 会理县| 宁乡县| 宁海县| 汾阳市| 阿克陶县| 牟定县|