As a working professional in Data Analytics, I have always been fascinated by new and upcoming ways of extracting data to create meaningful insights. There is a myriad of options for a data analyst to explore. However, some fit better than the others in certain contexts. In light of this possibility, I decided to explore the world of R.
This post is helpful for anyone who has just begun learning R and would like to have a brief introduction of the language and its features before completely immersing into its limitless possibilities. It covers some commonly asked questions on R, Objects in R (basics). I will write a more detailed post on R’s features in my next post.
What is R?
R is both a programming language and a free software for analytics and graphics. It runs on pretty much any operating system and is widely used among statisticians and data miners for data analysis and presentations.
Is R fit for people who have no programming experience?
Yes! Anyone who has never done programming before can start with R for two primary reasons :
- R is an interpreted language, not a compiled one, meaning that all commands typed on the keyboard are directly executed without requiring to build a complete program
- The syntax of R is very simple and intuitive
However, there is no denying that anyone with a prior programming experience has an advantage. But this should certainly not be a reason to not learn it, in case of individuals who are new to the coding world.
What are the available sources online that will help me understand the basics of R?
Well, if you’re on DataScience+, you have already answered this question. Often books (such as R for Data Science) and courses can just give you the theoretical knowledge that may seem hard to apply while actually implementing them. This is where blog posts and data science communities help. A weekly reading of new posts related to R for beginners, sample writing of codes, understanding basic features goes a long way in actually understanding any language that one might be interested in learning.
What do i need in order to start my R programming?
Just make sure you download the latest version of R Studio and meet all the system requirements that have been laid down. RStudio gives you a way to talk to your computer. R gives you a language to speak in.
The RStudio interface is simple. You type R code into the bottom line of the RStudio console pane and then click Enter to run it. The code you type is called a command because it will command your computer to do something for you. The line you type it into is called the command line.
When you type a command at the prompt and hit Enter, your computer executes the command and shows you the results. Then RStudio displays a fresh prompt for your next command.
For eg:
1+1 [1] 2
You’ll notice that a [1] appears next to your result. R is just letting you know that this line begins with the first value in your result.
Now that we have had a brief yet important introduction to R, let’s go through some simple concepts of R programming :
What are objects in R?
R lets you save data by storing it inside an R object. What’s an object? Just a name that you can use to call up stored data.
- To create an R object, choose a name and then use the less-than symbol, <, followed by a minus sign, -, to save data into it. This combination looks like an arrow, <-. R will make an object, give it your name, and store in it whatever follows the arrow.
- When you ask R what’s in a, it tells you on the next line.
- You can use your object in new R commands, too. Since a previously stored the value of 1, you’re now adding 1 to 2.
Eg :
a <- 1 a [1] 1
a + 2 [1] 3
Rules for writing down the names of Objects :
You can name an object in R almost anything you want, but there are a few rules. First, a name cannot start with a number. Second, a name cannot use some special symbols, like ^
, !
, $
, @
, +
, -
, /
, or *
Also, a very important point to note is that R will overwrite any previous information stored in an object without asking you for permission. So, it is a good idea to not use names that are already taken.
You can see which object names you have already used with the function ls:
Eg: If you have already stored values in Objects with name such as “a”, “name”, “fruits_box”, you can see these names with the ls()
function
ls() [1] "a" "name" "fruits_box"
These were some of the most basic and the simplest of R concepts today. Practice codes for storing values in Objects and performing different arithmetic operations on them. Get familiar with the interface of R and read more about it online.
In my next post, I intend to cover some more basic concepts and sample codes that can we write with the help of their understanding.
Happy Learning!