So what actually is R? Let’s take a look at running some commands, and we can talk about it as we go along.
R is a powerful environment for statistical computing
It is like a calculator and its power is:
… it lets you save results in variables. Let’s take a look:
> z = 4
> x + y + z
Ok, so we can run little commands and it gives us numbers back. What’s all the fuss about?
We can save data in files. They are saved as .RData files. R lets us import and export data in lots of different ways. If it sounds fun, it is because it is! Let’s take a look.
> save(someData, file = “D:/DataAnalystsToolkit/someData.Rdata”)
Well, that is great if our data is in RData format. But normally we need to import data from different sources.
Import from CSV File
Alternatively we can load data in directly from RStudio.
Go to Tools in RStudio, and select Import Dataset.
Select the file CountryCodes.csv and select the Import button.
In RStudio, you will now see the data in the data pane.
The console window will show the following:
> #import dataset
> CountryCodes <- directory="" files="" header="F)
Once the data is imported, we can check the data.
So how do we connect R to SQL Server?
The Package RODBC provides R with a connection to ODBC databases:
# or read query from file
# myQuery <- ataanalyststoolkit="" myquery.sql="" nchars="99999)