R studio is structured with Frames. There is a frame that is the Console (where R commands are typed in), a frame that shows the Data Frames and other things, a frame showing the Environment, and a frame showing Files, Packages, etc.
Before starting each session, you need to have the following package turned on in R Studio: mosaic
RStudio has some Data Frames built in, such as NHANES that you can use. You would need to turn on the NHANES package.
Important: R is case sensitive. If you want to find a mean, then you have to type mean. If you type Mean, R will not know what you are asking it to do. If you name a variable Weight, then you must use Weight every time you use it. If you type weight, R will not know what variable you are using. I suggest always using lower case when naming variables and upper case when naming Data Frame. That way you are consistent and can remember.
Note: the generic names Data Frame and variable are used through these commands. Please name your Data Frame something that makes sense for the data and then use that name in place of Data Frame in all commands. For the variable, find the names of the variables used in the Data Frame file and use that in place of variable.
The command Data Frame%>% allows the Data Frame to be used in the next line of code and there is no need to specify the Data Frame in the next line. The command Data Frame%>% must be used in every string of commands so R knows where the data is.
The basic structure of almost all commands in this class is:
goal(y~x, data=Data Frame, …)
Where goal is what you want R to do, ie create a graph, calculate some statistics, or inferential statistics. y is the variable that is on the vertical axes and is the dependent variable. x is the variable that is on the horizontal axes and is the independent variable, do note there can be more than 1 independent variable. The Data Frame is the name of your Data Frame. The … means that there are options that you can do if you want to, though you don’t have to. The symbol ~ is the tilde symbol that is in the upper left of the keyboard. It can be thought of “is related to” or “is a function of.”
You can copy any of the output from R Studio by highlighting it and then crtl C (or command C on a Mac). To copy a graph, click on the graph, then go to Export in that same window. The easiest way is to choose Save as an Image. Then right click (option click on a Mac) on the image and then save the image to your computer. Then you can insert the image into your word processing program. You can also use snip it to screen grab the graph or grab it on a Mac.
To read the Data Frame into R Data Frame<-c(web address of csv file) To look at the structure of the data set: head(Data Frame) Though R Studio also shows you the Data Frame if you click on the name of the Data Frame you want.
You can also load your Data Frame into RStudio. Create the Data Frame in Excel or Google Sheets. The Data Frame must be tidy data. That means that each row belongs to one individual, and all the variable names are one word. I suggest that they are lowercase and describe what the variable is for the Data Frame. Then save the file as a csv file using the name of the file to be what you want the Data Frame to be named in R Studio. In R Studio, in the frame that has the files, plots, packages, etc., under Files, click on Upload and find the file on your computer. Say OK. Now under Files, click on the name of the file you uploaded and then Import Data Frame. The Data Frame will now be accessible to you in RStudio.
If you want you can load a googlesheet into R Studio. You need the package googlesheets installed an loaded. Then the command is Data Frame<-gs_title(“google sheet name”) The first time you do this, your google drive will ask you for permission to do this and give you a code that you then copy back into R Studio. Once you have done this, redo the command to read the Data Frame in. Future googlesheets are read in just be changing to the name of the googlesheet in quotes.
Then do: New_Data Frame<-Data Frame%>% + gs_read(ws=“google sheet name”)