DANL 200: Introduction to Data Analytics

Author

Marcus Smith

Published

February 19, 2024

1 Markdown Syntax

Plain text

DANL and DANL

DANL and DANL

1.1 Dive into Markdown syntax

Check out Classwork 3 - Markdown Basics



2 R Basics

“Tidy datasets are all alike, but every messy dataset is messy in its own way.” — Hadley Wickham

R is a powerful language and environment for statistical computing and graphics. It is widely used among statisticians and data analysts for data analysis and developing statistical software. Here are some basic concepts and elements of R to help you get started:



2.1 1. R as a Calculator

R can be used as a simple calculator. You can perform arithmetic operations like addition (+), subtraction (-), multiplication (*), and division (/). For example, typing 2 + 2 in the R console will give you 4.



2.2 Variables

Variables in R are used to store data. You can create a variable using the assignment operator <- (option/Alt + -). For example:

Code
my_variable <- 10

This will store the value 10 in my_variable.



2.3 Data Types

  • R has several basic data types:

    • Numeric: For decimal values like 2.5.
    • Integer: For whole numbers like 2L (the L tells R it is an integer).
    • Character: For text or string values, e.g., "Hello".
    • Logical: For boolean values (TRUE or FALSE).



2.4 Vectors

Vectors are a basic data structure in R. They contain elements of the same type. You can create a vector using the c() function:

Code
my_vector <- c(1, 2, 3, 4, 5)



2.5 Data Frames

Data frames are used for storing data tables in R. It is a list of vectors of equal length. For example, to create a simple data frame:

Code
df <- data.frame(
  Name = c("Alice", "Bob"), 
  Age = c(25, 30)
  )



2.6 Functions

Functions are used to carry out specific tasks in R. For example, sum() is a function that adds numbers together:

Code
sum(1, 2, 3) # Returns 6
[1] 6



2.7 Packages

R has a vast collection of packages for various statistical tasks. You can install a package using install.packages("packageName") and load it using library(packageName).



2.8 Help System

To get help on a specific function or topic, use the help() function or the shorthand ?, like ?sum on R Console.





3 References