last update: 2021-07-28

R Space

 

You are floating in R Space, alone but for your data

What you will learn

 

  • Basic data types in R, str()
  • Categorical data
  • class() and converting variables
  • Vector and matrix fun

Basic data types in R, str()

 

Data objects are storage containers

 

x <- 1 # single numeric integer

y <- c(4.43, 2.70) # vector of numeric decimal values

z <- c("Bob", "Karen") # vector of character strings

The Global environment “R space”

 

The Global environment “R space”

 

Variable name conventions

 

  • Can contain letters, numbers, some symbolic characters

  • Must begin with a letter

  • Must not contain spaces

  • No forbidden characters like ‘+’, ‘-’, ‘@’, and others

  • Should be human-readable, consistent, and not too long

  • Case sensitive

Factors

 

A factor is data where the different values are categories

  • Ordered factor

'Monday', 'Tuesday', 'Wednesday...'

  • Non-ordered factor

"Staffordshire", "Lancashire"...

 

Generally need to think about this when analysing data

class() and converting variables

 

  • The class() function can be use to see what R thinks your variable class is

  • Also, the Global Environment

Vectors and matrices

 

Vector

  • stores data in a single dimension from 1 to i, my_vec[i]

Matrix

  • stores data in two dimensions 1 to i rows, 1 to j columns my_mat[i, j]

Array

  • 3 dimensions to i, j, and k my_array[i, j, k]

Live coding

Â