2/13/2017

Intro to Visual Studio 2015 R Ingesting Data Files

This blog post is second in a series on Intro to Visual Studio 2015 R Project.  In this blog we'll discuss data and how to connect to files.
 
We start off in the Visual Studio 2015 IDE.  From the R Interactive window, we enter the command:
 
getwd() to get the "working directory" of our project.
 
Once we know that, we can add our files to the folder, or we can set the working directory using the command:
 
setwd("C:\Users\jbloom\Desktop\Statistics\data")
 
Now we defined our folder, we can add our files here.
 
Back in the IDE, we enter our command to ingest the contents of our file.  In this case, we start off with a CSV or comma separated value file
 
mydata = read.csv("Income1.csv")
 
The variable "mydata" contains the contents of our file.  If we want to view the contents, we type the command:
 
fix(mydata)

This spawns a new pop up window displaying the data:


You can double click a cell, change the value by copy, paste or delete, or typing manually, close the window, reopen, you'll see the new value(s) still appear.

Now we try a .txt file:

Auto = read.table("Auto.txt", header = T, na.strings = "?")

fix(Auto)


To see it's dimensions, type:

dim(Auto)

we get back:

[1] 397 9

To see the first 4 rows:

Auto[1:4,]


To get rid of Null Values (NA):

Auto = na.omit(Auto)

[1] 392 9

You may notice 7 less rows as before due to the Null rows.

To display the field names:

names(Auto)

We get:


[1] "mpg" "cylinders" "displacement" "horsepower" "weight" "acceleration" "year" "origin"
[9] "name"    

And that sums up our Intro to Visual Studio 2015 R Ingest Data Files.
 
To reference the first blog in the series, check out:

http://www.bloomconsultingbi.com/2017/02/intro-to-visual-studio-2015-r-project.html

Thanks for reading~!

Top 22 Complaints by Number