# This document is from Stat 135, Spring 07 # It covers some basic R features inclding: # Vectors, Assignments, extraction, and getting help # You can make comments like this # Equality means assigning the thing on the right to the left a = 3 # Alternatively, one can use an arrow a <- 3 6 -> b # Just don't do this 3 = a # There are several data structures, we first consider vectors scoresM = c(5,8,3,5,2) vec = 1:5 scores vec # or all at once scores; vec # note that R can be used as a calculator 2^4 - 1 # Most functions that operate on scalars operate # pointwise on vectors (1:10)^2; exp( scoresM ); 1:10 + 1:10 a+b ls() # see what is in your workspace rm(a) # remove an object a+b # doesn't work because you removed a # you can paste things together and extract from them vec1 = 1:10 vec2 = c(3,7,14) vec3 = c( vec1, vec2 ) vec3 vec3[12] vec3[7:12] vec3[-(7:12)] # we can generate a vector of random numbers data = rnorm(10^4) data hist(data) ################### HOW TO GET HELP ################### ?rnorm help(rnorm) # both are the same, you can also enter up top # If you aren't using a GUI, then open the # browser and go to search engine and keywords help.start() # note how there are default values rnorm(10,50) # 10 normals with mean 50 and variance 1 ######################################################## # someone tells you about the function hist hist(data) # someone tells you about the function truehist truehist(data) # But you get an error ?truehist # then try help.search('truehist') #the indication is that MASS needs to be added library(MASS) truehist(data)