Term
assign a value to a variable |
|
Definition
by using the assignment operator, which is just a 'less than' symbol followed by a 'minus' sign. It looks like this: <- |
|
|
Term
|
Definition
a small collection of numbers, a single number is considered a vector of length one |
|
|
Term
Any object that contains data |
|
Definition
is called a data structure, numeric vectors are the simplest type of data structure in R |
|
|
Term
easiest way to create a vector |
|
Definition
is with the c() function, which stands for 'concatenate' or 'combine'. To create a vector containing the numbers 1.1, 9, and 3.14, type c(1.1, 9, 3.14). |
|
|
Term
Numeric vectors can be used in arithmetic expressions, z*2+100 |
|
Definition
First, R multiplied each of the three elements in z by 2. Then it added 100 to each element to get the result you see above. |
|
|
Term
|
Definition
|
|
Term
|
Definition
|
|
Term
The simplest way to create a sequence of numbers in R |
|
Definition
is by using the `:` operator |
|
|
Term
|
Definition
|
|
Term
|
Definition
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10 |
|
|
Term
|
Definition
30 numbers between 5 and 10, inclusively and evenly |
|
|
Term
let my_seq<-seq(5,10,length=30), then length(my_seq)=? |
|
Definition
|
|
Term
|
Definition
|
|
Term
|
Definition
|
|
Term
|
Definition
|
|
Term
|
Definition
40 zeros, rep = "replicate) |
|
|
Term
|
Definition
replicate vectors, which results in 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 |
|
|
Term
|
Definition
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 |
|
|
Term
|
Definition
An atomic vector contains exactly one data type |
|
|
Term
|
Definition
whereas a list may contain multiple data types |
|
|
Term
let num_vect<-c(0.5,55,-10,6), then tf<-num_vect<1 |
|
Definition
print(tf) results in TRUE FALSE TRUE FALSE 4 logical values, The statement num_vect < 1 is a condition and tf tells us whether each corresponding element of our numeric vector num_vect satisfies this condition. |
|
|
Term
|
Definition
The `<` and `>=` symbols in these examples, Other logical operators include `>`, `<=`, `==` for exact equality, and `!=` for inequality. |
|
|
Term
|
Definition
If we have two logical expressions, A and B, we can ask whether at least one is TRUE with A | B (logical 'or' a.k.a. 'union') |
|
|
Term
|
Definition
whether they are both TRUE with A & B (logical 'and' a.k.a. 'intersection') |
|
|
Term
|
Definition
!A is the negation of A and is TRUE when A is FALSE and vice versa |
|
|
Term
|
Definition
Double quotes are used to distinguish character objects, as in the following example. Eg: my_char<-c("My","name","is") |
|
|
Term
paste(my_char,collapse=" ") |
|
Definition
"My name is". Use paste(my_char, collapse = " ") to collapse the words in the vector so they almost form a sentence. There should be a single space between the double quotes in the `collapse` argument so that there are single spaces separating the words. |
|
|
Term
my_name<-c(my_char, "Jason") |
|
Definition
To add (or 'concatenate') your name to the end of my_char, use the c() function like this: c(my_char, "your_name_here"). |
|
|
Term
paste("Hello", "world!", sep=" ") |
|
Definition
|
|
Term
paste(1:3,c("X","Y","Z"),sep="") |
|
Definition
|
|
Term
paste(LETTERS,1:4,sep="-"), vectors of different length |
|
Definition
"A-1" "B-2" "C-3" "D-4" "E-1" "F-2" "G-3" "H-4" "I-1" "J-2" "K-3" "L-4" "M-1" "N-2" "O-3" "P-4" "Q-1" "R-2" "S-3" "T-4" "U-1" "V-2" "W-3" "X-4" "Y-1" "Z-2" (recycling) |
|
|