To improve our student experience, the Student Portal will be temporarily closed for scheduled upgrades from Noon ET on Thursday, February 1st, to Noon ET on Monday, February 5th.

Calculating Descriptive Statistics using RStudio

If you haven’t already, you will need to download and install R and Rstudio from the following page: https://posit.co/download/rstudio-desktop/ 

Before you begin working with RStudio, you need to be sure that you’ve installed the packages that you need to perform the operations you desire.

For basic statistics, you will need to install the fBasics package. Follow these steps: 

  1. Tools
  2. Install Packages
  3. Type fBasics under Packages 
  4. Click Install

Now that you’ve installed the package you need to perform basic descriptive statistics, it is time to import your data. Complete the following steps:

  1. In the upper right window in RStudio, click on the Environment tab.
  2. Click Import Dataset
  3. Browse to find your data.
    1. If you have an Excel file, R will import it with any issue.
    2. If you have a CSV file, this needs to be imported as “From Text (base)”
  4. Once R has captured the data (you’ll see it displayed in the window), click Import.
  5. Now you will see your data displayed as a new tab in the text area (upper left window).

The next step is to attach the file.  In this step, R is given access to perform operations on the data.  It is a good idea to type your commands into the text area (upper left window) then click on Run.  When you click on Run, you’ll see the command executed in the console window (lower left window).  The reason for following this procedure is to keep a record of what you’ve typed so you can save it or examine it for issues (debug your commands).  

To attach the file, type the following: 

attach(filename)

As you begin to type the filename, RStudio will automatically complete the file name for you.  This is a great feature to be aware of as you work with variable names as well. 

Now you will need to let RStudio invoke the library of tools that you want to apply.  Since we have just installed fBasics, you will type the following:

library(fbasics)

To view the descriptive statistics for one variable, use the following command: 

summary(variable)

As you type the name of the variable, RStudio will provide you with a selection to choose from so you can select the correct variable. 

To view the descriptive statistics for ALL variables in the file, type the following: 

basicStats(data.frame(variable1, variable2, …)

Please note, that if you get values in scientific notation,  you can use the following command to put the numbers into normal numerical format:

options(scipen=999)