Shared Flashcard Set

Details

R Programming
R Programming
31
Computer Science
Undergraduate 3
05/18/2014

Additional Computer Science Flashcards

 


 

Cards

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
vector
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
take the square root
Definition
sqrt() function
Term
take the absolute value
Definition
abs() function
Term
The simplest way to create a sequence of numbers in R
Definition
is by using the `:` operator
Term
seq(1,20)
Definition
same as 1:20
Term
seq(1,20,by=0.5)
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
seq(5,10,length=30)
Definition
30 numbers between 5 and 10, inclusively and evenly
Term
let my_seq<-seq(5,10,length=30), then length(my_seq)=?
Definition
30
Term
1:length(my_seq)
Definition
equal to 1:30
Term
seq(along=my_seq)
Definition
equal to 1:30
Term
seq_along(my_seq)
Definition
equal to 1:30
Term
rep(0, times = 40)
Definition
40 zeros, rep = "replicate)
Term
rep(c(0,1,2),times=10)
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
rep(c(0,1,2), each=10)
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
atomic vector
Definition
An atomic vector contains exactly one data type
Term
lists
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
logical operators
Definition
The `<` and `>=` symbols in these examples, Other logical operators include `>`, `<=`, `==` for exact equality, and `!=` for inequality.
Term
A | B
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
A & B
Definition
whether they are both TRUE with A & B (logical 'and' a.k.a. 'intersection')
Term
!A
Definition
!A is the negation of A and is TRUE when A is FALSE and vice versa
Term
Double quotes ""
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
"Hello world!"
Term
paste(1:3,c("X","Y","Z"),sep="")
Definition
"1X" "2Y" "3Z"
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)
Supporting users have an ad free experience!