Introduction to R Data Wrangling Lisa Federer MLIS

  • Slides: 12
Download presentation
Introduction to R: Data Wrangling Lisa Federer, MLIS, MA, AHIP Research Data Informationist

Introduction to R: Data Wrangling Lisa Federer, MLIS, MA, AHIP Research Data Informationist

Course Overview • Introduction to R and RStudio – Why R? – What is

Course Overview • Introduction to R and RStudio – Why R? – What is RStudio? – Terminology and syntax • Hands-on practice – Deciphering error messages and troubleshooting – Basics of data processing/wrangling – Getting more help

Why R? One command to carry out complex tasks

Why R? One command to carry out complex tasks

Why R? Easy to share code, which enhances reproducibility

Why R? Easy to share code, which enhances reproducibility

Why R? Everything in one places: data processing, analysis, and visualization

Why R? Everything in one places: data processing, analysis, and visualization

What is RStudio? IDE (integrated development environment) for R

What is RStudio? IDE (integrated development environment) for R

Data input options • Input data directly into R by typing it in •

Data input options • Input data directly into R by typing it in • Import data from many, many common file types (. txt, . csv, Excel files, XML, SAS, SPSS, Stata, etc) • Connect to web resources and other remote servers

Data types: data frame a list of variables of the same number of rows

Data types: data frame a list of variables of the same number of rows with unique row names (like a spreadsheet)

Data types within data frames • Numeric variable = numeric or integer Ex: 1,

Data types within data frames • Numeric variable = numeric or integer Ex: 1, 1. 5, 200000, 3. 14159 • Text variable = character Ex: a, b, hello, 3 b • Nominal variable = factor Ex: cat, dog, pig, rhino, horse • Ordinal variable = ordered factor Ex: xsmall, medium, large, xlarge • True/false = logical Ex: TRUE, FALSE

Talking to R getwd() dat <- read. csv(file = "all. Found. csv", header =

Talking to R getwd() dat <- read. csv(file = "all. Found. csv", header = TRUE) Function: how to tell R what to do, always followed by ()

Talking to R getwd() dat <- read. csv(file = "all. Found. csv", header =

Talking to R getwd() dat <- read. csv(file = "all. Found. csv", header = TRUE) Argument: instructions that specify how a function should be run. Not always required, may be more than one, they are separated by commas, and they all go in the ()

Talking to R getwd() dat <- read. csv(file = "all. Found. csv", header =

Talking to R getwd() dat <- read. csv(file = "all. Found. csv", header = TRUE) Assignment operator (<-): assigns the output of the function to a name that you can then refer back to