Professional Documents
Culture Documents
3. Sequence of numbers
Symbol: increase or decrease in 1.
seq(begin, end, by=increment)
seq(begin, end, length=30)
length() gives length of sequence
If :length() sequence will have that length
seq(along.with=)
seq_along()
rep() Repeat number n times
rep(c(0,1,2),times=10) Repeats vector 10 times
rep(c(0,1,2),each=10) Repeats each number 10 times
4. Vectors
Same class
>, <, =<, >=, ==, != are logical operators
| or, & and, !A negation
paste( , collapse = ) joins vector
paste( , sep = ) Joins 2 different characters
The thing between the is what is going to separate the character
5. Missing values
NA Not available
Operations with NA result in NA
rnorm() draws from standard normal distribution
sample()
is.na()
sum()
NaN not a number
6. Sub setting vector
7. Matrices and Data Frames
Rectangular data types
Matrices: one class of data
Data frames: more than one class
dim() ##tells the dimension of an object
Can also be used to set the dimensions of an object
dim()<-c( , )
length() ##tells the length of an object
attributes() ##tells the attributes of the object
class() ##tells the class of an object
matrix(data,row,col) ## creates matrix from given set of values
identical() ##tells if 2 objects are identical
cbind() ## combines columns
implicit coercion changes classes
data.frame() ## creates a data frame composed of the original objects
colnames() #assign name to columns
8.
Boolean values: TRUE FALSE
== ##identical
!= ## not equal
<, >, >=, <=
& ## and operator (&& evaluates the first)
| ##or operator (|| evaluates the first)
First and then or (order of evaluation)
isTRUE() ##
evaluates if expression is true
identical() ##true if 2 arguments are identical
xor() ##exclusive or, TRUE if one argument false and the other true
sample() ##random
which() ## tells which objects cover the condition
any() ## TRUE if any is true all()## TRUE if all
Functions
Sys.Date() ## Tells the date
Mean()
function_name <- function(arg1, arg2){# Manipulate arguments in
some way
# Return a value}
To find the source code of function just type the function without arg.
Args() ##shows the arguments of the function