R

Session 104
King Chung Huang
Portfolio Manager

What is R

R

|ɑːr|
noun

R (continued)

Why R

R Language

Variables

	> x = 3.14     # assign 3.14 to x
	> x            # print the value of x
	[1] 3.14

Numerics, integers

	> x = 3.14
	> class(x)     # print the class name of x
	[1] "numeric"  # numer is essentially “double”

	> y = as.integer(3.14)
	> y
	[1] 3
	> class(y)
	[1] "integer"
	> is.integer(y)
	[1] TRUE

Logical

	> t = TRUE
	> f = FALSE
	> class(t)
	[1] "logical"
	> t
	[1] TRUE
	> !t
	[1] FALSE
	> t & f      # t AND f
	[1] FALSE
	> t | f      # t OR f
	[2] TRUE

Character

	> n = 'Nancy'
	> x = as.character(3.14)
	> class(x)
	[1] "character"
	> paste(n, x)      # combine strings
	[1] "Nancy 3.14"
	> sprintf("%s has %d dollars", n, as.double(x))
	[1] "Nancy has 3.14 dollars"

Vector

List

Frame

Time for Action

Load Data

Scatter Plot

Histogram

Facebook Friends

Twitter

Exercise

Fork me on GitHub