Skip to content
Variables and Assignment
step 1/5

Reading — step 1 of 5

Learn

~1 min readThe Vector Mindset

R uses <- for assignment by convention (also = works, but <- is the idiomatic R style).

x <- 5
name <- "Ada"
pi_value <- 3.14159

R has these basic types:

  • numeric — double-precision floats (the default for numbers)
  • integer — append L: 42L
  • character — strings, double or single quotes
  • logicalTRUE, FALSE (or T, F)
  • NA — missing value (one per type, e.g. NA_integer_)
  • NULL — absence of value

class(x) tells you the type. typeof(x) is more granular.

x <- 5
class(x)        # "numeric"
class(5L)       # "integer"
class("hi")     # "character"

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…