| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Getting Started

Page history last edited by Don 13 years, 5 months ago

Getting Started


Overview of Steps

     In order to view the results, we will want to:

  1. Open the R command line interpreter
  2. Import data and read in the data
  3. Attach the data
  4. Import the  software libraries we want to use to view the data
  5. Practice generating graphs
  6. Save graphs as files

 

Create a Working Directory

Then create a directory to save our output:

In  Linux enter:

mkdir ~/linuxwithR

 

cd ~/linuxwithR

 

 

makedirlinuxwithr.png

Download the data:

          You can go to this link and save the file http://misterdavis.org/r_wiki/r_results_1231_2010

          CSV and XLS files are also available.

 

Or using the command line simply type:

wget http://misterdavis.org/r_wiki/r_results_1231_2010

 

At the command line start R by typing:

R

 

Loading Data

 

Loading a data file

I. Importing data
We import data as a data set using the read csv function. (CSV – comma separated variables is a text only format. Excel files are also available. The csv file has been created to have relatively sane headers which are easily digestible for R. )

We will type:
newlpp=read.csv("r_results_1231_2010")

 


(Another method of loading the file: newlpp = read.csv(file.choose(), headers=T)

The downloaded file has been edited to remove incomplete rows and to parse some data for better readability. The original file is available here.
Note – do not forget the quotation marks or the import will fail.

 

Changing Max Size

The database with answers from the 4603 respondents exceeds the default limit of rows R will print. The file we are using is relatively large. In order to view all rows, we will want to increase our maxprint size.
Enter the following:
options(max.print=5.5E5)

 

 

Checking Contents 

Check to see that the data has been imported and all lines are viewable:
print(newlpp)

You should see all 4603 rows. There are several columns; you may only see the last few as print wraps around. If you receive an error message such as:
reached getOption("max.print") -- omitted 3234 rows
you will want to adjust the max print size as discussed above.

 

Attaching Data

An import next step is 'attaching' our data so that R knows it is the data we want to work with.

 

To 'attach' the data so that we can run queries and analyze it, enter the following:
attach(newlpp)

 

rcommandsimportdata2.png

To see the column names we enter:
names(newlpp)

 

rcommandsimportdata3.png

We now have the data ready. However, later, we will want to import additional libraries for working with data.

 

<---Previous     Index      Next--->

Comments (0)

You don't have permission to comment on this page.