R has five basic or “atomic” classes of objects:
-
@@ -73,11 +73,11 @@
diff --git a/02_RProgramming/DataTypes/Introduction to the R Language.pdf b/02_RProgramming/DataTypes/Introduction to the R Language.pdf
index cec046b60..b8f1bc492 100644
Binary files a/02_RProgramming/DataTypes/Introduction to the R Language.pdf and b/02_RProgramming/DataTypes/Introduction to the R Language.pdf differ
diff --git a/02_RProgramming/DataTypes/index.Rmd b/02_RProgramming/DataTypes/index.Rmd
index 65eb1ce54..19f8f1af4 100644
--- a/02_RProgramming/DataTypes/index.Rmd
+++ b/02_RProgramming/DataTypes/index.Rmd
@@ -8,7 +8,7 @@ framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
url:
- lib: ../../libraries
+ lib: ../../librariesNew
assets: ../../assets
widgets : [mathjax] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
@@ -200,7 +200,9 @@ NAs introduced by coercion
> as.logical(x)
[1] NA NA NA
> as.complex(x)
-[1] 0+0i 1+0i 2+0i 3+0i 4+0i 5+0i 6+0i
+[1] NA NA NA
+Warning message:
+NAs introduced by coercion
```
---
@@ -472,4 +474,4 @@ Data Types
- data frames
-- names
\ No newline at end of file
+- names
diff --git a/02_RProgramming/DataTypes/index.html b/02_RProgramming/DataTypes/index.html
index 9b50617cb..00c65c081 100644
--- a/02_RProgramming/DataTypes/index.html
+++ b/02_RProgramming/DataTypes/index.html
@@ -8,46 +8,46 @@
-
-
+
-
-
-
Roger Peng, Associate Professor
Johns Hopkins Bloomberg School of Public Health
Roger Peng, Associate Professor
Johns Hopkins Bloomberg School of Public Health
R has five basic or “atomic” classes of objects:
Numbers in R a generally treated as numeric objects (i.e. double precision real numbers)
R objects can have attributes
At the R prompt we type expressions. The <- symbol is the assignment operator.
> x <- 1
@@ -145,11 +145,11 @@ Entering Input
When a complete expression is entered at the prompt, it is evaluated and the result of the evaluated expression is returned. The result may be auto-printed.
> x <- 5 ## nothing printed
@@ -165,11 +165,11 @@ Evaluation
> x <- 1:20
> x
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
@@ -182,11 +182,11 @@ Printing
The c() function can be used to create vectors of objects.
> x <- c(0.5, 0.6) ## numeric
@@ -208,11 +208,11 @@ Creating Vectors
What about the following?
> y <- c(1.7, "a") ## character
@@ -226,11 +226,11 @@ Mixing Objects
Objects can be explicitly coerced from one class to another using the as.* functions, if available.
> x <- 0:6
@@ -248,11 +248,11 @@ Explicit Coercion
Nonsensical coercion results in NAs.
> x <- c("a", "b", "c")
@@ -263,18 +263,20 @@ Explicit Coercion
> as.logical(x)
[1] NA NA NA
> as.complex(x)
-[1] 0+0i 1+0i 2+0i 3+0i 4+0i 5+0i 6+0i
+[1] NA NA NA
+Warning message:
+NAs introduced by coercion
Matrices are vectors with a dimension attribute. The dimension attribute is itself an integer vector of length 2 (nrow, ncol)
> m <- matrix(nrow = 2, ncol = 3)
@@ -293,11 +295,11 @@ Matrices
Matrices are constructed column-wise, so entries can be thought of starting in the “upper left” corner and running down the columns.
> m <- matrix(1:6, nrow = 2, ncol = 3)
@@ -311,11 +313,11 @@ Matrices (cont’d)
Matrices can also be created directly from vectors by adding a dimension attribute.
> m <- 1:10
@@ -332,11 +334,11 @@ Matrices (cont’d)
Matrices can be created by column-binding or row-binding with cbind() and rbind().
> x <- 1:3
@@ -356,11 +358,11 @@ cbind-ing and rbind-ing
Lists are a special type of vector that can contain elements of different classes. Lists are a very important data type in R and you should get to know them well.
> x <- list(1, "a", TRUE, 1 + 4i)
@@ -382,11 +384,11 @@ Lists
Factors are used to represent categorical data. Factors can be unordered or ordered. One can think of a factor as an integer vector where each integer has a label.
> x <- factor(c("yes", "yes", "no", "yes", "no"))
> x
[1] yes yes no yes no
@@ -421,11 +423,11 @@ Factors
The order of the levels can be set using the levels argument to factor(). This can be important in linear modelling because the first level is used as the baseline level.
> x <- factor(c("yes", "yes", "no", "yes", "no"),
@@ -439,11 +441,11 @@ Factors
Missing values are denoted by NA or NaN for undefined mathematical operations.
> x <- c(1, 2, NA, 10, 3)
> is.na(x)
[1] FALSE FALSE TRUE FALSE FALSE
@@ -478,11 +480,11 @@ Missing Values
Data frames are used to store tabular data
> x <- data.frame(foo = 1:4, bar = c(T, T, F, F))
> x
foo bar
@@ -520,11 +522,11 @@ Data Frames
R objects can also have names, which is very useful for writing readable code and self-describing objects.
> x <- 1:3
@@ -542,11 +544,11 @@ Names
Lists can also have names.
> x <- list(a = 1, b = 2, c = 3)
@@ -565,11 +567,11 @@ Names
And matrices.
> m <- matrix(1:4, nrow = 2, ncol = 2)
@@ -584,11 +586,11 @@ Names
Data Types