#################### # Module 2 - Lab # 1/5/15 #################### ## In this lab you can use the interactive console to explore ## but please record your commands here. ## Remember anything you type here can be "sent" to the console with ## Cmd-Enter (OS-X) or Cntr-Enter (Windows/Linux). # 1. create a new variable called 'my.num' that contains 7 numbers my.num = c(12,5,2,76,3,54,1) # 2. mulitply 'my.num' by 4 my.num*4 # 3. create a second variable called 'my.char' that contains 6 character strings my.char = c("a","re", "e","bge", "de", "we") # 4. combine the two variables 'my.num' and 'my.char' into a variable called 'both' both = c(my.num, my.char) # 5. what is the length of 'both'? length(both) # 6. what class is 'both'? class(both) # 7. divide 'both' by 3, what happens? both/3 # 8. create a vector with elements 1 2 3 4 5 and call it x x = c(1,2,3,4,5) x = 1:5 # 9. create another vector with elements 10 20 30 40 and call it y y = c(10,20,30,40) y = seq(10,40,by=10) # 10. what happens if you try to add x and y together? why? x+y # 11. append the value 50 onto the vector y (hint: you can use the c() function) y = c(y,50) # 12. add x and y together x+y # 13. multiply x and y together. pay attention to how R performs operations on vectors of the same length. x*y