0% found this document useful (0 votes)
12 views19 pages

RStudio and Its Procee 7

The document provides an overview of R and RStudio, highlighting R as a free programming language for statistical computing and RStudio as a user-friendly integrated development environment. It details various features of RStudio, including the workspace, history tab, and how to manage working directories and scripts. Additionally, it covers package management, plotting capabilities, and resources for further learning about R.

Uploaded by

arpitasri1305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views19 pages

RStudio and Its Procee 7

The document provides an overview of R and RStudio, highlighting R as a free programming language for statistical computing and RStudio as a user-friendly integrated development environment. It details various features of RStudio, including the workspace, history tab, and how to manage working directories and scripts. Additionally, it covers package management, plotting capabilities, and resources for further learning about R.

Uploaded by

arpitasri1305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Content

 R Studio GUI

 Steps or Procedure
Introduction
 R is a free, open-source software and programming language
developed in 1995 at the University of Auckland as an
environment for statistical computing and graphics.

 RStudio allows the user to run R in a more user-


friendly environment. RStudio is an integrated development
environment (IDE) that allows you to interact with R more
readily. It is open-source (i.e. free) and available at
http://www.rstudio.com/

2
RStudio screen

3
RStudio Windows and Description
Workspace tab (1)
 The workspace tab stores any object, value, function or
anything you create during your R session. In the example
below, if you click on the dotted squares you can see the data
on a screen to the left.

5
Workspace tab (2)
 Here is another example on how the workspace looks like
when more objects are added. Notice that the data frame
house.pets is formed from different individual values or
vectors.
Click on the dotted square to look at the
dataset in a spreadsheet form.
History Tab

 The history tab keeps a record of all previous commands. It


helps when testing and running processes. Here you can either
save the whole list or you can select the commands you want
and send them to an R script to keep track of your work.
In this example, we select all and click on the “To Source” icon, a window on the left will open with the list of
commands. Make sure to save the ‘untitled1’ file as an *.R script.
Changing the working directory
1

If you have different projects you can change the


working directory for that session, see above. Or you can
type:

# Shows the working directory (wd)

getwd()

# Changes the wd

setwd("C:/myfolder/data")

More info see the following 3


document:
http://dss.princeton.edu/training/RStata.p
df
Setting a default working directory
1

2
3
Every time you open RStudio, it goes to a default
directory. You can change the default to a folder
where you have your datafiles so you do not have
to do it every time. In the menu go to Tools-
>Options

4
R script (1)
The usual RStudio screen has four windows:
1. Console.
2. Workspace and history.
3. Files, plots, packages and help.
4. The R script(s) and data view.
The R script is where you keep a record of your work. For Stata users this
would be like the do-file, for SPSS users is like the syntax and for SAS
users the SAS program.
R script (2)
To create a new R script you can either go to File -> New -> R Script, or click on the
icon with the “+” sign and select “R Script”, or simply press Ctrl+Shift+N. Make
sure to save the script.

Here you can type R commands and run


them. Just leave the cursor anywhere on
the line where the command is and press
Ctrl-R or click on the ‘Run’ icon above.
Output will appear in the console below.
Packages tab
The package tab shows the list of add-ons included in the installation of RStudio. If
checked, the package is loaded into R, if not, any command related to that package
won’t work, you will need select it. You can also install other add-ons by clicking on
the ‘Install Packages’ icon. Another way to activate a package is by typing, for
example, library(foreign). This will automatically check the --foreign package (it
helps bring data from proprietary formats like Stata, SAS or SPSS).
Installing a package

Befor
e

1
 We are going to install the
package – rgl (useful to plot 3D
images). It does not come with
2 the original R install.
 Click on “Install Packages”,
3  write the name in the pop-up
 window and click on “Install”.
Afte r
Plots tab (1)

The plots tab will display the


graphs. The one shown here is
created by the command on line 7
in the script above.
See next slide to see what happens
when you have more than one
graph
Plots tab (2)

Here there is a second graph (see


line 11 above). If you want to see
the first one, click on the left-
arrow icon.
Plots tab (3) – Graphs export
To extract the graph, click on “Export” where you can save the file as an image (PNG, JPG, etc.) or as
PDF, these options are useful when you only want to share the graph or use it in a LaTeX document.
Probably, the easiest way to export a graph is by copying it to the clipboard and then paste it directly into
your Word document.

3 Make sure to select ‘Metafile’


5 Paste it
into your
Word
document

4
1
5
3D graphs

3D graphs will display on a separate screen (see line 15


above). You won’t be able to save it, but after moving it
around, once you find the angle you want, you can
screenshot it and paste it to you Word document.

1
6
Resources
 For R related tutorials and/or resources see the following
links: http://dss.princeton.edu/training/
http://libguides.princeton.edu/dss

You might also like