############ # Lec 1 ls() # lists whats in workspace head(dat) # shows first entries of dat tail(dat) # shows last entries of dat rep(foo, n) # repeats foo n times c() # collects items into one vector class(dat) # shows the class of dat dat$sex # only on data.frames: selects the sex vector of dat table() # creates a one or two way table scan() # reads in data from any source. be careful with its options '<-' '=' # assignment operators dim() # the dimensions of a matrix or data.frame, doesn't work on vectors ############ # Lec 2 read.table() # reads in a file as a data.frame read.csv() # reads in a .csv file as a data.frame getwd() # displays your current working directory setwd() # sets your working directory head(dat) # displays first elements of dat tail(dat) # displays last elements of dat names(data.frame) # displays column names of data.frame str(dat) # displays attributes of dat unique(dat) # returns unique elements of dat length(dat) # length of a vector x[index] # returns x indexed by numbers contained in 'index' is.na(dat) # checks for missing / NA elements of dat which(test) # returns indices of true elements ifelse(test, yes, no) # can be used to created binary variables write.table # writes an R object to a file