# 01_Open_R # The window that holds this file is the editor. ## Here you can create command files - like do files in STATA # The window below is the console. ## There you will see the code and the answer as it is executed. # The window on the top right shows the data objects. ## currently this should be empty, but if you type a = matrix(1,2,3), or b = 3 you can see these objects. # The bottom right window shows file resources, packages, help files and Plots. # lets return to the console (bottom window), if you haven't done so type: a = matrix(1,3,3) b=3 # look at the object in the console by directly calling it. b a # now click on a # => it opens in the editor, you will have to close it or return to this file. # => This is how you can browse data objects. # to run code from the file you have to highlight it and hit the "=>Run" button on top. Try this on the next line: c= b*a # this is also how you can run multiple commands such as: d= a e= d*c f= a-e dim(f) # sometimes we want functions that are not loaded g= inv(c) # ups error-message: a package is missing. (I googled it: its "matlib") # to install a new package, ## 0.) if you don't know the name of the package you need, tell google what you want to do "in r", e.g. "machine learning in R" ## 1.) Once you know the name of the package go to the resources window and find "packages." ## 2.) If the package is not there click "install" and search for the package: e.g. "matlib" ## 3.) hit install. ## 4.) now matlib will apear in the list of installed packages and you can click on it to load it. # alternatively the following lines do the same: install.packages("matlib") library(matlib) #ok, now back to our inverse: g= inv(c) # hmm, are these now our matrix algebra limitations? Let's try this: h= matrix(c(1, 2, 3, 2, 4, 5, 3, 4, 6), nrow=3, ncol=3) i= inv(h) j = h*i ## any guess what j might be? ## use %*% for matrix multiplication l= h%*%i ## Lastly, Random Number.m m= runif(1) ## and random vectors n= runif(12) ## Random Number between 1 and 100 o<- sample(1:100, 1) o p<- sample(1:100, 7) p ## you can run code directly from the console