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
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
getting and setting workspace
In [2]:
# to display current working directory use getwd() function
getwd()
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.
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/
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
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.
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.
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.
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)
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
ReplyDeleteWonderful 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
ReplyDeleteYou 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
ReplyDeleteYoure 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
ReplyDeleteyou 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
ReplyDeleteI 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
ReplyDeleteGreat Article
R Project Topics for Computer Science
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
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!
ReplyDeleteLink building in Singapore
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
ReplyDeleteYou 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.
ReplyDeleteI 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
ReplyDeleteHi,
ReplyDeleteI 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.
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.
ReplyDeleteHiya! 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
ReplyDeleteAPTRON 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.
ReplyDeleteFor More Info: Data Science Course in Gurgaon
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
ReplyDelete