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]:
help(mean)

getting and setting workspace

In [2]:
# to display current working directory use getwd() function
getwd()
'C:/Users/Suresh/mlclassscripts'
In [ ]:
# to set up workspace or working directory use setwd() function
#syntax is shown below
setwd("path")
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
documentation
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 [ ]:
help("stats")
help("mean")
args("mean")
example("mean")

#getting help documentation for a package
help(package="caret")

online help for R programming

We can get online help on available packages in R from official website of R-Cran
https://cran.r-project.org/web/views/
We can also get online support for our day to day activities from below websites:
https://stackoverflow.com/
https://stats.stackexchange.com

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
install.packages("randomForest")

#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
library(cluster)
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.
if(!library(cluster)){
install.pacakges("cluster")
}

basic operations in R

In [ ]:
# Adding two numericals
1+1

#multiplying two numericals
10*2

#dividing two numericals
10/2

#applying modulus operation on two numericals
10%%2

printing results to R console

In [ ]:
#printing the data on the console
print(10*2)

print("data science")

print(pi^2)

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 [ ]:
data()
In order to load a specific dataset into R, we need to give the dataset name as argument to the data() function
In [ ]:
data(AirPassengers)

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 [ ]:
head(AirPassengers)
to view all the records in a nice tabular view
In [ ]:
View(AirPassengers)

Getting the description and structure of R object

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

41 comments:

  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  9. 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.

    ReplyDelete
  10. 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

    ReplyDelete
  11. 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

    ReplyDelete
  12. 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

    ReplyDelete
  13. 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

    ReplyDelete
  14. 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

    ReplyDelete
  15. 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

    ReplyDelete
  16. 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

    ReplyDelete
  17. 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

    ReplyDelete
  18. 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

    ReplyDelete
  19. 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

    ReplyDelete
  20. 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

    ReplyDelete
  21. 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

    ReplyDelete
  22. 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

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

    ReplyDelete
  24. 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

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

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

    ReplyDelete
  27. 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.

    ReplyDelete
  28. I like this post, Thanks. The best photography,video & media services in Penrith, New South Wales.
    https://www.robertpalejsphotography.com/

    ReplyDelete
  29. 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.

    ReplyDelete
  30. 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.

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

    ReplyDelete
  32. 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.

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

    ReplyDelete
  34. 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

    ReplyDelete