R Tutorials | Statistics and Data Analysis with R | #rstats
https://global-fintech.blogspot.com/2016/02/r-statistics-data-analysis.html
What is R?
Using R or R-Studio for Data Analysis and Statistics |
#rstats
Installing R
Linux, Windows, Mac
Rconsole, RStudio R online
Installing R
Linux, Windows, Mac
Rconsole, RStudio R online
Packages and Libraries
Basic commands in R
First and foremost, we need to be able to manipulate data in R.
1. Our first action would be to find a working directory or set a new one in R (functions getwd() and setwd() in R). The procedure is the following:
2. Next, we enter our data. In R, we can 1) enter the data manually or 2) load an already existing data file:
1) creating the dataset (function data.frame()) and entering the data manually (function edit()) in R:
2) loading a data file in R (reading a .csv or a .txt file) by means of the R function read.table():
We can enter either the entire address or just the name of the file provided that we have specified the working directory (see above - getwd() and setwd()) |
3. Having loaded the data file, we need to upload it (or 'attach') to the working memory of R - attach():
4. To open or visualise a file in R, we type its name in R:
5. We can analyse the structure of the data file by means of the R function str():
6. Finally, we can save the data file (e.g. in .csv format) by using the function write.csv():
7. Other important commands in R:
- to add a variable to a dataset, we can use the command cbind():
cbind(mydata, weight)
- to recode a variable, we use the function recode():
country<- recode(region, '"OECD"=1; else=2; ', as.factor.result=TRUE)
- to order information in a file in an increasing/decreasing order with respect to a variable, we use the command order():
mydata[order(-weight),]
- to create a subset of a dataset, we use the command subset():
OECD<-subset(mydata, subset=(region=="OECD"))
- to define a variable as a label variable, we use the function row.names():
row.names(mydata)<-number
Using R for Statistics
1. Descriptive Statistics with R
2. Linear and Multivariate Regression with R
3. Principal Component Analysis (PCA) with R
2. Linear and Multivariate Regression with R
3. Principal Component Analysis (PCA) with R
4. Hierarchical Clustering Models (HCM) with R
More info about R as well as other R language tutorials you can find on the homepage of the R programming language - r-project.org as well as on r-bloggers.com, a website which accumulates the knowledgebase of the R programming language all over the net. You are also very welcome to subscribe to the R-bloggers' podcast - http://feeds.feedburner.com/RBloggers.