Tuesday, August 1, 2017

Learn R : Statistical Programming Language Part 1


    SQL Server 2016 supports running R code in SQL Server using stored procedures. This feature created a new way to query the data in SQL Server. Microsoft introduced this feature under R Services. With Python support in SQL Server 2017, Microsoft changed the package name from R Services to Machine Learning package. To be able use or explore this functionality, you need to know R.
    I am going show you the basics of R language in this post. Please check my older blog about how to setup R Services/Machine Learning in SQL Server side and client side to learn about the setup process. You don't need to install anything today to learn the basics of R. We will worry about querying SQL data later. I am going to use R-Fiddle for demos, It's free and you don't need to install anything.

R Expressions

Let's start with variables, to store data in a variable you need to use  <-


       As you can see, you don't need to specify a type for a variable, I just give a name without type  to call it later. Also just like JavaScript you can re-assign any value to any variable at any time. You can use T as a shorthand for TRUE and F as a shorthand for FALSE.

R Functions

     Nothing is new here, To call a function, you need to type its name, followed by one or more arguments to that function in parenthesis. Here is some basic functions.


     rep() function a value multiple times.To get help about any function you can call help(function_name), To get an example of a usage a function you can call example(function_name).
To repeat a value, you can use rep function.

R Vectors

     Vectors are list of values. R uses vectors for many of its operations and graphs. Vector's values can be any type as long as they are all the same type! Here are some samples for creating array of values by using c function. c is short for Combine.


     As you can see, when you mix the types in the list, R converts all of the values into string type.
If you need a sequence of numbers, you can create it with start:end notation. Here is an example using : notation to create a vector.


You can do the same thing with seq() function. Seq() function allows you to change increments.


    We can use the index number of a vector to access an individual value in a vector. Unlike many languages R's vector indices start with 1. To get the first value of a vector, you need to pass 1 rather than 0. You can insert/edit vector values by using start:end notation too.



      If you like to give names to the vectors items, we need to create another vector and attach it to our current vector.


     We can do all kind of calculations with vectors, Here is some examples. Since R is an analytic language, It doesn't surprise me to have this kind of functionality.

      R Fiddle is a great tool and location to practice R, Visual R Tools is a great Visual Studio addition if you like to use Visual Studio. Extension is available in Community version, so you don't need to have full paid version to practice and learn R. I will continue to write about R in my next posts.

23 comments:

  1. To be honest as a trainer it is very informative and helpful article. You are doing amazing job indeed. We are also doing same for the IT education. For more about us plz visit Learn R Programming

    ReplyDelete
  2. It's amazing blog And useful for me Thanks
    It's Very nice , Thanks for sharing
    iOS App Development Online Training

    ReplyDelete

  3. Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us big data training in Velachery | Hadoop Training in Chennai | big data Hadoop training and certification in Chennai | Big data course fees

    ReplyDelete
  4. Your post is really awesome. Your blog is really helpful for me to develop my skills in a right way. Thanks for sharing this unique information with us.Data Science Online Training

    ReplyDelete
  5. Thanks for such a great article here. I was searching for something like this for quite a long time and at last, I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays.
    Python Training in Noida

    ReplyDelete
  6. Nice, it was definitely interesting for me to read about their market situation nowadays.
    AWS Training in Delhi

    ReplyDelete
  7. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information.
    Python Training in Noida

    ReplyDelete
  8. It was really a nice post and I was really impressed by reading this keep updating
    Nice work, your blog is concept-oriented, kindly share more blogs like this
    Tableau Training

    Android App development Course

    Data Science course

    Dot net Course

    Ios Development Course Online

    Informatica Training

    ReplyDelete
  9. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Data Science with R Programming training in Electronic City

    ReplyDelete
  10. It's a Nice post! Thank you for sharing your knowledge to others, it was very informative and in depth one.
    R Training in Electronic City

    ReplyDelete
  11. Thanks for such useful information with clear content.Your information will help how how to use R,from beginner basics to advanced techniques from R Programming Training Institute in Bangalore

    ReplyDelete
  12. Great post! It's really helpful to see the basics of R language explained clearly, especially for those who are new to data analysis and machine learning. It's also good to know that there are free tools like R-Fiddle available for learning and practicing. As a .Net developer in Delhi,I can see the potential for incorporating R and machine learning into our projects, and I appreciate the guidance on how to set it up in SQL Server. Thanks for sharing!



    ReplyDelete