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

Write R Markdown Files for Code Reproducibility

The considerable success of analytics is a result of the way the information and knowledge network around the subject started to spread. More open source communities emerged, developers were happily sharing their work with the outer world, and many data projects were becoming reproducible. This change meant that work started by one person was soon getting adapted, improvised, and modified in many different forms by a community of people before it got adopted in an entirely different domain than the one from where it initially emerged. Imagine every research work that gets published in conference submitting a collection of code and data that is easily reproducible along with their research paper. This change is accelerating the pace at which an idea meets reality, and innovation will start to boom.

Now, let's see how to create such reproducible work in a single file that we call the R Markdown file. In the following activity, we will demonstrate how to create a new R Markdown file in RStudio. A detailed intro to R Markdown could be found at https://rmarkdown.rstudio.com/lesson-1.html.

In the next activity, you will recreate the code shown in Exercise 4, Reading a CSV File with Text Column and Storing the Data in VCorpus, into an R Markdown. Observe in Figure 4.2 that you have just written the explanation and the code in R Markdown, and when the Knit to Word action is performed, it interweaves the explanation, code, and its output neatly into a word document.

Activity 1: Create an R Markdown File to Read a CSV File and Write a Summary of Data

In this activity, we will create a R Markdown file to read a CSV file and print a small summary of the data in a word file:

Perform the following steps to complete the activity:

  1. Open RStudio and navigate to the R Markdown option:

    Figure 1.4: Creating a new R Markdown file in Rstudio

  2. Provide the Title and Author name for the document and select the Default Output Format as Word:

    Figure 1.5: Using the read.csv method to read the data

  3. Use the read.csv() method to read the bank-full.csv file.
  4. Finally, print the summary into a word file using the summary method.

    The output is as follows:

Figure 1.6: Final output after using the summary method

Note

The solution for this activity can be found at page 438.

主站蜘蛛池模板: 小金县| 金秀| 宿迁市| 堆龙德庆县| 依安县| 横山县| 嘉禾县| 普兰店市| 阿荣旗| 茂名市| 天柱县| 海南省| 棋牌| 亚东县| 三江| 昆明市| 沽源县| 晴隆县| 石泉县| 嵊州市| 阳山县| 金川县| 青川县| 秭归县| 遂川县| 荔波县| 吉木萨尔县| 郸城县| 马关县| 颍上县| 安西县| 延津县| 泰安市| 壤塘县| 英德市| 德兴市| 惠水县| 蕲春县| 湘潭市| 台江县| 滕州市|