Textual Formats
dumping and dputing are useful because the resulting textual format is edit-able, and in the case
of corruption, potentially recoverable.
Unlike writing out a table or csv file, dump and dput preserve the metadata (sacrificing some
reada

Removing NA Values
A common task is to remove missing values (NAs).
> x <- c(1, 2, NA, 4, NA, 5)
> bad <- is.na(x)
> x[!bad]
[1] 1 2 4 5
12/14
Removing NA Values
What if there are multiple things and you want to take the subset with no missing values?
> x

Subsetting a Matrix
Matrices can be subsetted in the usual way with (i,j) type indices.
> x <- matrix(1:6, 2, 3)
> x[1, 2]
[1] 3
> x[2, 1]
[1] 2
Indices can also be missing.
> x[1, ]
[1] 1 3 5
> x[, 2]
[1] 3 4
4/14
Subsetting a Matrix
By default, when a s

Subsetting
There are a number of operators that can be used to extract subsets of R objects.
[ always returns an object of the same class as the original; can be used to select more than one
element (there is one exception)
[ is used to extract elements

Names
R objects can also have names, which is very useful for writing readable code and self-describing
objects.
> x <- 1:3
> names(x)
NULL
> names(x) <- c("foo", "bar", "norf")
> x
foo bar norf
1
2
3
> names(x)
[1] "foo" "bar" "norf"
24/27
Names
Lists ca

Objects
R has five basic or atomic classes of objects:
character
numeric (real numbers)
integer
complex
logical (True/False)
The most basic object is a vector
A vector can only contain objects of the same class
BUT: The one exception is a list, whi

Missing Values
Missing values are denoted by NA or NaN for undefined mathematical operations.
is.na() is used to test objects if they are NA
is.nan() is used to test for NaN
NA values have a class also, so there are integer NA, character NA, etc.
A Na

Matrices
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)
> m
[,1] [,2] [,3]
[1,]
NA
NA
NA
[2,]
NA
NA
NA
> dim(m)
[1] 2 3
> attributes(m)
$dim
[

Creating Vectors
The c() function can be used to create vectors of objects.
>
>
>
>
>
>
x
x
x
x
x
x
<-
c(0.5, 0.6)
c(TRUE, FALSE)
c(T, F)
c("a", "b", "c")
9:29
c(1+0i, 2+4i)
#
#
#
#
#
#
numeric
logical
logical
character
integer
complex
Using the vector()