Getting Started
Overview of Steps
In order to view the results, we will want to:
- Open the R command line interpreter
- Import data and read in the data
- Attach the data
- Import the software libraries we want to use to view the data
- Practice generating graphs
- Save graphs as files
Create a Working Directory
Then create a directory to save our output:
In Linux enter:
mkdir ~/linuxwithR
cd ~/linuxwithR
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)
To see the column names we enter:
names(newlpp)
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.