Blog posts on Data Science, Machine Learning, Data Mining, Artificial Intelligence, Spark Machine Learning

Saturday, December 2, 2017

Getting Started with R

In this post we get familiar with R Studio and basic syntax of R programming language

Rstudio OverView

we have 4 panes
1) script pane - to write and save the programing script
2) Console pane - where all the code will get executed
3) Environment/history pane - displays all the variables created,functions
used with in the current session
4) Helper pane - contains multiple tabs to install/display pacakges,
view visualization plots,
locate files within the workspace

In [1]:

getting and setting workspace

In [2]:
# to display current working directory use getwd() function
In [ ]:
# to set up workspace or working directory use setwd() function
#syntax is shown below
In [6]:
setwd("C:\\Suresh\\R&D\\Projects\\ML classroom training\\sessions")
setwd("C:/Suresh/R&D/Projects/ML classroom training/sessions")

getting help in R

To get help within R environment, we use help() function to get the
for any of the functions/packages available within R environment.
To see the arguments required for a function, we use args() function.
to see the example of a function, example() function is used.
In [ ]:

#getting help documentation for a package

online help for R programming

We can get online help on available packages in R from official website of R-Cran
We can also get online support for our day to day activities from below websites:

Installing Packages

In [ ]:
#install pacakges in R can be done in two ways,
#1) using install.packages() function and from the bottom right pane of Rstudio

#loading of installed or downloaded packages can be done using library() function.  
#Note that we can only load the package if
# we have installed the package already within our R environment
In [ ]:
#below code to first verify if the library is installed in the R environment, 
#if it is not available
# then the package will get installed.

basic operations in R

In [ ]:
# Adding two numericals

#multiplying two numericals

#dividing two numericals

#applying modulus operation on two numericals

printing results to R console

In [ ]:
#printing the data on the console

print("data science")


Variable declaration and assignment in R

variable assignment: In the below example, we are creating variable named z:
In [8]:
z <-  100
we use left arrow or = symbol for variable assignment. Its always good
practice to use left arrow for assignment.
In [9]:
z = 10.009
z <- 10.009

Loading existing or default datasets available in R environment

we can access default datasets avaiable in R using data() function.
data() function will displays all the avaiable datasets within R.
In [ ]:
In order to load a specific dataset into R, we need to give the dataset name as argument to the data() function
In [ ]:

Viewing data of R objects

To view first 5 records of a R object (ex:dataframe), we use head() function.
head() function expects the data object as argument and prints the first 5 records on the R console.
In [ ]:
to view all the records in a nice tabular view
In [ ]:

Getting the description and structure of R object

use str function to see the descriptions of the data object,
In [ ]:


  1. Hey! Would you mind if I share your blog with my myspace group? There's a lot of folks that I think would really enjoy your content. Please let me know. digital marketing agency

  2. Wonderful blog! I found it while browsing on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I've been trying for a while but I never seem to get there! Thanks internet marketing company singapore

  3. You made some first rate points there. I seemed on the internet for the issue and found most individuals will go together with along with your website. phonak hearing aids

  4. Youre so cool! I dont suppose Ive read anything like this before. So nice to find somebody with some original ideas on this subject. realy thank you for beginning this up. this website is something that is wanted on the internet, somebody with just a little originality. useful job for bringing something new to the web! Yoox

  5. you are really a good webmaster. The website loading speed is incredible. It seems that you are doing any unique trick. Moreover, The contents are masterpiece. you have done a fantastic job on this topic! reputation management

  6. I get pleasure from, lead to I discovered exactly what I was looking for. You have ended my four day long hunt! God Bless you man. Have a nice day. Bye. web design in singapore

  7. I don’t even know how I ended up right here, however I thought this submit was great. I do not recognise who you are however certainly you're going to a well-known blogger when you aren't already ;) Cheers!
    Link building in Singapore

  8. Wow! Thank you! I constantly wanted to write on my site something like that. Can I take a portion of your post to my website? seo plan

  9. You could certainly see your enthusiasm in the work you write. The world hopes for more passionate writers like you who are not afraid to say how they believe. Always go after your heart.

  10. I was wondering if you ever thought of changing the layout of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or 2 images. Maybe you could space it out better? strategy for serious digital marketer

  11. Hi,
    I found your web site by means of Google while looking for a related subject, your site got here up I will make sure to bookmark it and come back to read more of your useful information. I really appreciate this post.

  12. If you were to buy domain singapore, you should look for MediaOne. The agency should be able to handle your specific needs and requirements in the right manner. They would ensure that you would have a significant presence in the online realm.

  13. Hiya! I just want to give a huge thumbs up for the nice information you've right here on this post. I can be coming back to your blog for extra soon. mammogram singapore

  14. APTRON is the top training provider accredited by the International Association of Business Analytics Certifications who is offering Data Science course in Gurgaon. The professionals trained from us gain the capabilities of being well-rounded, data-driven people with high-quality technical skills who are ready to manufacture complex quantitative algorithms which can organize and synthesize large amounts of crude data.
    For More Info: Data Science Course in Gurgaon

  15. Howdy this is kinda of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I'm starting a blog soon but have no coding experience so I wanted to get guidance from someone with experience. Any help would be enormously appreciated! safety shoes Singapore

  16. Hello! I simply would like to give an enormous thumbs up for the good information you've gotten here on this post. I will probably be coming back to your weblog for extra soon. drums class in chennai

  17. I do not even know how I ended up here, but I thought this post was good. I do not know who you are but certainly you're going to a famous blogger if you aren't already ;) Cheers! scandinavian interior design singapore

  18. That is stunning! I'm passed up the character of the astounding.I've perused a great deal of articles, this really is one of the greatest ones that I've perused. Carry on providing more articles this way. Singapore funeral parlour

  19. I'm still learning from you, while I'm trying to achieve my goals. I absolutely liked reading all that is posted on your site.Keep the tips coming. I loved it! special needs trust

  20. I don’t even know how I ended up here, but I thought this post was good. I do not know who you are but certainly you're going to a famous blogger if you are not already ;) Cheers! blotting paper

  21. Exceptional post however I was wondering if you could write a litte more on this subject? I'd be very thankful if you could elaborate a little bit further. Cheers! List of Asset Management Companies in Singapore

  22. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
    ai training in patna

  23. I'm really enjoying the design and layout of your website. It's a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work! Marble Dining Table Singapore

  24. Incredible! This blog looks exactly like my old one! It's on a entirely different subject but it has pretty much the same layout and design. Wonderful choice of colors! tactical gear

  25. That is really attention-grabbing, You're a very skilled blogger. I have joined your rss feed and sit up for in quest of extra of your great post. Additionally, I have shared your web site in my social networks!

    supply chain masters degree

  26. I love your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz respond as I'm looking to construct my own blog and would like to know where u got this from. aircon gas top up

  27. I love your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz reply as I'm looking to construct my own blog and would like to find out where u got this from. pest control

  28. Outstanding post but I was wondering if you could write a litte more on this topic? I'd be very thankful if you could elaborate a little bit more. Cheers!
    queen size mattress

  29. Howdy! This is my first remark here so I simply needed to give a brisk holler and reveal to you I truly appreciate perusing your posts. Would you be able to suggest some other online journals/sites/discussions that manage similar points? Much obliged!

    event cleaning

  30. Can anyone provide me a tutorial that I could use to learn how Rstudio.
    custom logo design company

  31. Fascinating article thank you for sharing them, I trust you will keep on having comparative presents to share with everybody. Also, we provide step wise instructions on performing SBCglobal Outlook Settings on MS Outlook account. For more information visit our website. SBCglobal Outlook Settings

  32. Thank you for this kind of post . It is very helpful

  33. Great survey, I'm sure you're getting a great response.

  34. Great information!!! Thanks for your wonderful informative blog.
    Village Talkies a top-quality professional corporate video production company in Bangalore and also best explainer video company in Bangalore & animation video makers in Bangalore, Chennai, India & Maryland, Baltimore, USA provides Corporate & Brand films, Promotional, Marketing videos & Training videos, Product demo videos, Employee videos, Product video explainers, eLearning videos, 2d Animation, 3d Animation, Motion Graphics, Whiteboard Explainer videos Client Testimonial Videos, Video Presentation and more for all start-ups, industries, and corporate companies. From scripting to corporate video production services, explainer & 3d, 2d animation video production , our solutions are customized to your budget, timeline, and to meet the company goals and objectives.
    As a best video production company in Bangalore, we produce quality and creative videos to our clients.

  35. I like this post, Thanks. The best photography,video & media services in Penrith, New South Wales.

  36. Nice post. Are you looking for a nice coffee shop?
    Head Chef Cafe and Coffee Shop in Deeside, United Kingdom. The best service and customer friendly Cafe and Restaurant in Deeside. All day British breakfast. Custom meals and much more.

  37. Thank you for your valuable and useful information through the blog. I am appreciating with the way you shared the relevant, precious, and perfect information. Furthermore, I would like to also keep some sound knowledge of Ac Service and Repair in Lucknow. If you have Need Of Any Type Of AC Service and Repair Service in Lucknow so just visit our website.

  38. Really good post! it's a very informative article Keep sharing more useful and informative articles. Thank you
    Online shop

  39. Digi Uprise offers an excellent online course that requires three months to complete. It includes everything from fundamentals of marketing to content strategy. It's perfect for those looking to establish an foundation in Digital Marketing Course in Rajouri Garden and be able to find an employment opportunity quickly. This is a more mentor-led method of learning the full stack of digital marketing expertise through real-world projects. This is an excellent option to those who are looking to up their education one step and learn from industry professionals on a monthly basis, through regularly scheduled video chats. It's a much more hands-on approach than standard video tutorials, that can result in more confidence and more success.

  40. Nice Blog....You brought up some excellent points. aircon gas top up

  41. If someone want to learn mobile app development, this blog is awesome. But, to hire someone for your mobile app development you can visit competenza