Programming & Data Analysis With

Programming & Data Analysis With

Programming & Data Analysis with ‘R’ Diarmuid O'Briain 2 Programming & Data Analysis with ‘R’ Copyright © 2018 Diarmuid Ó Briain Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". Document Outline This document brings together a collection of diferent R experiences. It documents work carried out during a week long training on “Statistical Data Analysis using R-software” that took place from 24 - 28 September 2018 at the Directorate of Research and Graduate Training (DRGT), Makerere University, Kampala, Uganda that was delivered by Associate Professor Matthew Low and Dr. Matthew Hiron of the Swedish University of Agricultural Sciences (SLU) to develop the programming aspect of R with a focus on the analysis of quantitative data sets. I have included a section on qualitative data analysis as R has some tools in that area too. The document explores the fundamentals of how to use R. Installing R, the structure of R, vectors, matrices, arrays, lists, tables, data-frames as well as fow control and user-defned functions. Working with quantitative data, linear models, predictions, probability distributions, distribution models and generalised linear mixed models. Plotting data for visual output. Finally both inductive and deductive approaches to the analysis of qualitative data is explored. Diarmuid Ó Briain Data Analytics Programming & Data Analysis with ‘R’ 02 Oct 2018 Programming & Data Analysis with ‘R’ 3 Table of Contents 1. INSTALLING R..............................................................................................................................................9 2. INTRODUCTION...........................................................................................................................................9 2.1 SIMPLE R SCRIPT.......................................................................................................................................9 2.2 ANOTHER SIMPLE SCRIPT........................................................................................................................10 2.3 START A NEW SCRIPT..............................................................................................................................10 2.4 RUNNING AN R SHELL..............................................................................................................................11 2.5 R ERRORS................................................................................................................................................11 2.6 COMMENTING...........................................................................................................................................11 2.7 LISTING THE EXISTING OBJECTS IN R......................................................................................................13 3. R STRUCTURE...........................................................................................................................................15 4. GETTING HELP WITH FUNCTIONS.....................................................................................................17 4.1 ARGUMENTS OF A FUNCTION...................................................................................................................17 4.2 HELP().......................................................................................................................................................17 4.3 EXAMPLE()................................................................................................................................................17 5. R PACKAGES.............................................................................................................................................19 5.1 THE COMPREHENSIVE R ARCHIVE NETWORK (CRAN).........................................................................19 5.2 INSTALLING PACKAGES IN R....................................................................................................................19 5.3 CHECK INSTALLED PACKAGES.................................................................................................................19 6. CITING R IN PAPERS AND PUBLICATIONS.....................................................................................23 6.1 CITE R......................................................................................................................................................23 6.2 CITE INDIVIDUAL R PACKAGES.................................................................................................................23 7. VECTORS, THE BASIC DATA STRUCTURE IN R.............................................................................25 7.1 EXERCISE: GENERATE VECTORS.............................................................................................................26 7.2 LENGTH() OF A VECTOR...........................................................................................................................27 7.3 VECTOR PRINCIPLES................................................................................................................................27 7.4 BOOLEANS................................................................................................................................................32 8. BUILDING ON VECTORS, OTHER DATA STRUCTURES IN R.....................................................37 8.1 BASICS OF STRUCTURES.........................................................................................................................37 8.2 RECAP EXERCISES....................................................................................................................................45 8.3 OPERATORS AS FUNCTIONS....................................................................................................................49 9. OUTPUT TO STANDARD OUT...............................................................................................................51 9.1 PRINT() AND CAT()....................................................................................................................................51 9.2 SPRINTF().................................................................................................................................................51 9.3 PASTE() AND PASTE0() FUNCTIONS.........................................................................................................52 9.4 NUMBERS.................................................................................................................................................53 9.5 CHARACTER STRING................................................................................................................................53 10. FLOW CONTROL & DATA FRAMES..................................................................................................55 10.1 IF & ELSE CONDITIONALS.......................................................................................................................55 10.2 IFELSE CONDITIONAL..............................................................................................................................55 10.3 LISTS......................................................................................................................................................57 10.4 TABLE.....................................................................................................................................................62 10.5 FOR() AND WHILE().................................................................................................................................62 10.6 DATA-FRAME..........................................................................................................................................63 10.7 INDEXING DATA-FRAMES.......................................................................................................................65 02 Oct 2018 Programming & Data Analysis with ‘R’ Data Analytics 4 Programming & Data Analysis with ‘R’ 10.8 ADD A NEW COLUMN..............................................................................................................................66 10.9 SINGLE OR DOUBLE BRACKETS FOR INDEXING?...................................................................................66 10.10 EXERCISE: DATA FRAME 1...................................................................................................................68 10.11 CHANGING NAMES WITHIN THE DATA..................................................................................................68 10.12 READ FILES INTO R..............................................................................................................................68 10.13 ENGLISH / EUROPEAN..........................................................................................................................69 10.14 SET A WORKING DIRECTORY...............................................................................................................69 10.15 CHECKS AFTER IMPORTING DATA-FRAME...........................................................................................69 10.16 REMOVING MISSING VALUES FROM A DATA SET.................................................................................69

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    204 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us