The Data Analysts Toolkit Day 4: Getting to know R a bit better

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:
> x
> y
> 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.
> someData
> save(someData, file = “D:/DataAnalystsToolkit/someData.Rdata”) 
> rm(someData) 
> load(“D:/DataAnalystsToolkit/someData.Rdata”) 
> print(someData)
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
Read.csv()
MyDataFrame

print(MyDataFrame)
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)
>   View(CountryCodes)
Once the data is imported, we can check the data.
dim(CountryCodes)
head(CountryCodes)
tail(CountryCodes) 
So how do we connect R to SQL Server?
The Package RODBC provides R with a connection to ODBC databases:
> library(RODBC) 
> myodbcConnect
myQuery

# or read query from file 
# myQuery <- ataanalyststoolkit="" myquery.sql="" nchars="99999) 
myData myodbcConnect

, myQuery, errors=TRUE) 

odbcCloseAll()
I hope that the rather bizarre colour coding will help you to see how the variables add up together to create a query.
RODBC also works for importing data from Excel files:
library(RODBC) 
filename
myxlsFile <- filename="" odbcconnectexcel="" readonly="FALSE) 
sqlSave(myxlsFile, a, rownames = FALSE) 
b
odbcCloseAll()
Next, we will look in more detail how R and PowerBI complement one another.


Share the Post:

Related Posts

Is Your Power BI a Spotlight or an Instagram Filter?

Power BI’s greatest value might not be the insights it delivers. Rather than masking the issues like an Instagram filter, Power BI may be your critical friend because of the problems it exposes. The wise thing to do is to use that signal to navigate your next step, rather than try to mask it as if it is an Insta filter. 

Read More

When Trusted Domains Betray Trust: Power BI Scam-Spam and the Case for Proactive BI Governance

Microsoft Power BI is facing increased phishing attacks that exploit its legitimate report subscription feature, allowing scammers to send malicious emails from trusted domains. Organisations need to recognise that Business Intelligence tools have functionality that could be used for good or bad. Governance means understanding the features, and using controls that recognise the fine line between business intelligence and cybersecurity.

Read More

From Pipes to Intelligence: Why Microsoft's FY25 Q2 Earnings Signal a New Era for AI ROI

Microsoft’s latest earnings call indicates a strategic shift towards prioritizing high-margin AI software over infrastructure. With 15 million Copilot users, the focus is on transforming enterprise value through active user engagement rather than mere license purchases. The emphasis on intelligence signals the future direction for organizations investing in AI.

Read More

Discover more from Jennifer Stirrup: AI Strategy, Data Consulting & BI Expert | Keynote Speaker

Subscribe now to keep reading and get access to the full archive.

Continue reading