Programming terms Flashcards
vector
c
myData[2]
second element
myData[-3]
all elements apart from the 3rd
myData[c(1,4)]
only 1st and 4th elements
myData[2:4]
2nd 3rd 4th elements
rep(3,4)
3333
4:7
4 5 6 7
seq(1,3)
1 2 3
seq(start,end,by = 2)
step of 2
seq(start,end length.out = 7)
has total of 7 elements evenly spaced
sum(1:10)
sum of all integers from 1 to 10
sum(seq(2,100,by =2))
sum all even integers between 1 and 100
x< - 1:4, x*x
1 4 9 16
x%*% x
matrix multiplication
x<- 1:4 , x+c(0,10)
1 12 3 14 recycles vectors when lengths are different
sort
sorts a vector
rank
provides the rank of each element
order
gives the indices of the elements in order
unique
returns just the unique values in the vector
table
provide counts of the occurrence of each element
length
total number of elements in the vector
sample
randomly sample from the elements of a vector
paste
concatenate a textual representation of vectors together
essential stats functions
mean, median, sd, var, min, max, range, quantile, cumsum