What are the commands for the most important mathematical operations in Julia and R? The following table translates the most common Julia commands into R language.
Julia  R  

Dot product  
dot(a,b) 
a%*%b 

Matrix multiplication  
A * B 
A%*%B 

Elementwise multiplication  
A .* B 
A * B 

Matrix to a power 

A^2 
require(exem) A%^%2 

Matrix to a power, elementwise 

A.^2 
A^2 

Inverse 

inv(A) 
solve(A) 

Determinant 

det(A) 
det(A) 

Eigenvalues and eigenvectors 

eig(A) 
eigen(A) 

Euclidean norm 

norm(A) 
norm(A, type="2") 

Solve least squares problem Ax = b 

A\b 
solve(a,b) 
Complete JuliaR Cheatsheet
1) Creating Vectors
2) Creating Matrices
3) Creating Random Numbers
4) Manipulating Vectors and Matrices
5) Accessing Vector/Matrix Elements
How to access vector and matrix elements in Julia and R? The following table translates the most common Julia commands into R language.
Julia  R  

Access one element  
A[2, 2] 
A[2, 2] 

Access specific rows  
A[1:4, :] 
A[1:4,] 

Access specific columns  
A[:, 1:4] 
A[,1:4] 

Concatenate vertically 

A = [[1 2]; [1 2]] 
A = rbind(c(1,2),c(1,2)) 

Remove a row 

A[[1, 2, 4], ] 
A[3, ] 

Diagonals of matrix 

diag(A) 
diag(A) 

Get dimensions of matrix 

size(A) 
dim(A) 
Complete JuliaR Cheatsheet
1) Creating Vectors
2) Creating Matrices
3) Creating Random Numbers
4) Manipulating Vectors and Matrices
5) Accessing Vector/Matrix Elements
How to manipulate vectors and matrices in Julia and R? The following table translates the most common Julia commands into R language.
Julia  R  

Transpose  
A.' 
t(A) 

Complex conjugate transpose  
A ' 
Conj(t(A)) 

Concatenate horizontally  
A = [[1 2] [1 2]] 
A = c(c(1,2),c(1,2)) 

Concatenate vertically 

A = [[1 2]; [1 2]] 
A = rbind(c(1,2),c(1,2)) 

Reshape (to 5 rows, 2 columns) 

A = reshape(1:10, 5, 2) 
A = matrix(1:10,5,2) 

Convert matrix to vector 

A[:] 
c(A) 

Repeat matrix (3 times in the row dimension, 4 times in the column dimension) 

repmat(A,3,4) 
kronecker(matrix(1,3,4),A) 

Flip Matrix form left to right 

flipdim(A, 2) 
A[,dim(A)[2]:1] 

Flip Matrix up/down 

flipdim(A, 2) 
A[dim(A)[1]:1,] 
Complete JuliaR Cheatsheet
1) Creating Vectors
2) Creating Matrices
3) Creating Random Numbers
4) Manipulating Vectors and Matrices
5) Accessing Vector/Matrix Elements
How to create random number in Julia and R? The following table translates the most common Julia commands into R language.
Julia  R  

Create uniform random numbers 

A = rand(10) 
A = runif(10) 

Create normal random numbers  
A = randn(10) 
A = rnorm(10) 

Create normal random numbers (mean=1,std=2) 

using Distributions A = rand(Normal(1,2),10) 
A = rnorm(10,1,2) 

Create Gamma distributed random numbers (shape=1,scale=2) 

using Distributions A = rand(Gamma(1,2),10) 
A = rgamma(10, shape = 1, scale = 2) 

Create Beta distributed random numbers (alpha=1,beta=2) 

using Distributions A = rand(Beta(1,2),10) 
A = rbeta(10,1,2) 
Complete JuliaR Cheatsheet
1) Creating Vectors
2) Creating Matrices
3) Creating Random Numbers
4) Manipulating Vectors and Matrices
5) Accessing Vector/Matrix Elements
How to create matrices in Julia and R? The following table translates the most common Julia commands into R language.
Julia  R  

Create a matrix  
A = [1 2; 3 4] 
A = matrix(c(1,2,3,4),2,2) 

Create a 2 x 2 matrix of zeros  
A = zeros(2,2) 
A = matrix(0,2,2) 

Create a 2 x 2 matrix of ones  
A = ones(2,2) 
A = matrix(1,2,2) 

Create a 2 x 2 identity matrix 

A = eye(2,2) 
A = diag(2) 

Create a diagonal matrix 

A = diagm([1;2;3;]) 
A = diag(c(1,2,3)) 
Complete JuliaR Cheatsheet
1) Creating Vectors
2) Creating Matrices
3) Creating Random Numbers
4) Manipulating Vectors and Matrices
5) Accessing Vector/Matrix Elements
How to create vectors in Julia and R? The following table translates the most common Julia commands into R language.
Julia  R  

Create a row vector  
A = [1 2 3] 
A = c(1,2,3) 

Create a column vector  
A = [1 2 3]' 
A = matrix(c(1,2,3),3,1) 

Create integers from j to n with step size k  
A = j:k:n 
A = seq(j,n,k) 

Create linearly spaced vector of k points  
A = linspace(1, 5, k) 
A = seq(0, 1, length.out = 10) 
Complete JuliaR Cheatsheet
1) Creating Vectors
2) Creating Matrices
3) Creating Random Numbers
4) Manipulating Vectors and Matrices
5) Accessing Vector/Matrix Elements
The following tutorial demonstrates how to seasonally adjust a time series in R using the ‘Seasonal’ package. For this purpose we use a R dataset called ‘AirPassengers’. This dataset contains the classic Box & Jenkins airline data. That is, the dataset contain the monthly totals of international airline passengers from 1949 to 1960. The data entail a high degree of seasonality, which become apparent when looking at the figure below.
Seasonal fluctuations make it difficult to interpret monthly changes of time series, i.e. it becomes difficult to determine how much of the change in a time series is due to fundamentals and how much of the change is due to seasonal factors. The seasonal adjustment procedure corrects the data for seasonal factors and produces data that are free of any seasonal influence. After seasonally adjusting data, we are now able to interpret monthly changes in the data and attribute this changes to fundamentals. The following figure displays both, the original series as well as the seasonally adjusted series. Note that the seasonally adjusted series in red is much smoother than the original. You can find the R code that seasonally adjusts data and produces these figures at the end of the post.
The following R code seasonally adjust the AirPassanger data and reproduces the figures included in this post.
# start with an empty workspace rm(list=ls()) # install and load seasonal package # install.packages("seasonal") library(seasonal) # use the R dataset AirPassengers. This dataset # contains the classic Box & Jenkins airline data. # Monthly totals of international airline # passengers, from 1949 to 1960. plot(AirPassengers) # seasonal adjust time series using X11. sa_series < seas(AirPassengers,x11 = "") # plot original and seasonally adjusted series. plot(AirPassengers) lines(final(sa_series),col=2)
I hope this list is a helpful overview of some advantages and disadvantages of using R. I am sure I have forgotten some things, so please add them in the comments.
There exists several reasons why one should start using R. During the last decade R has become the leading tool for statistics, data analysis, and machine learning. By now, R represents a viable alternative to traditional statistical programs such as Stata, SPSS, SAS, and Matlab. The reasons for R’s success are manifold.
First, R is an opensource language and computing environment than runs on many plattforms including Windows, Macintosh and Linux. The software is published under the Free Software Foundation‘s GNU General Public License, that allows every user to freely distribute, study, change, and improve the software.
Second, R is far more than a statistical package: it is a proper programming language. This is, one can create its own objects, functions, and packages. Technically, R is a free implementation of the S programming language. However, most code written in S will still run successfully in R. R provides a large variety of basic to advanced statistical and graphical techniques that come at little to no cost to the user.
Finally, R is becoming the standard. The advantages named above encourage the growing use of R in cutting edge social science research. R is well maintained by an active and highly talented community. Every user can develop and publish its own R package and further contribute to R’s success. Packages represent extensions to the base R and can easily be installed and used in R. Many packages are submitted by prominent members of their respective fields. Currently, there are over 10,000 packages available on the official repository for R packages, named CRAN. In order to give you an indication of R’s success, at the beginning of the decade CRAN only hosted little more than 2,000 packages. Some version of R is likely to remain popular for the indefinite future.
Hence, one can easily conclude that, as the emerging standard for statistical programming, it is likely to be a highly rewarding process to learn how to use R. The following post outlines the most Pros and Cons of R.