How to use apply() function in R

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! apply() function in R programming is used to perform a specified function, either a R base installation function or an user-written function, to the rows or columns of a matrix or data frame. The basic for of the function is : apply(object, axis, fun) Where object is a matrix or data frame, axis denotes Read more

Using probability functions in R

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! R provides rich availability of using probability functions. Probability functions in R takes the form [dpqr][prob], Where [dpqr] represent which kind of variates the function works on d – probability density p – cumulative probabilty q – quantile value r – random number generation [prob] denotes which probability distribution is taken on. The following Read more

Subseting datasets in R

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! When a data frame is created in R, usually parts of it will be used later. Subset of the dataset, either by row or by column, or both can be easily created in R. The following example, only data containing columns for ‘Math’, ‘Physics’, and ‘Chemistry’ are selected and assigned to a new object, Read more

Merging and combining datasets using merge(), rbind() and cbind() in R

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! R provides two functions which make combine different datasets easy and feasible. rbind() is used when two datasets have same column variables and data observations are combined and expanded, whereas cbind() combines two datasets when they have the same number of rows. And merge() is used when two datasets have common column variables. The Read more

How to generate random numbers from Normal, Uniform and Poisson distribution in R

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! Doing statistics using R is perfect for many data analysts. Dealing with various statistical distributions and generating random numbers from some widely used distributions are mandatory for data science. In this post, we show how to generate random numbers from Normal, Uniform and Poisson distributions in R. Normal variates can be generated by using Read more

How to generate a set of sample data using sample() function in R

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! sample() function in R selects random samples from a given population. The population can be all elements of a vector, observations of a data frame, etc. For example, in the following code example, 10 elements are randomly selected a population of 100 integers, with replacement possible. The basic form of sample() is sample(object, n, Read more

How to select observations of data frames in R

rdatacode.com provides online training course for R and Python, click here for more info ! When a data frame is applied in data analysis in R, very often some specific rows or observations may be selected. The simplest way to select observations is filling row indices in square brackets. Conditional test can be included into row selection. In the following example, Male students over 23 years old are selected. Date variable can be transformed to Read more

How to draw multivariate statistical data in R

rdatacode.com provides online training course for R and Python, click here for more info ! In simulation and Bayesian statistics, it is often needed to draw data coming from multivariate variables. R provides a function draw.d.variate.dist() from package ‘MultiRNG’ for such purpose. For example, draw.d.variate.normal() are used to draw multivariate random data coming from variables have joint normal distributions. In the following example, 200 random sample data are drawn from 3 variables which follow joint Read more

How to select variables in data frame with R

We provide online training for R and Python, click here for more info ! When a data frame is created in R, sometimes the data frame contains dozens of variables and only a subset of them will be used in data analysis. Thus, selecting these variables and saving them into a new object will make data management clear and concise. Say, we have a data frame about student testing score, ‘grade’ on hand. And now, Read more

How to drop variables from data frames in R

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! In this post we show several methods of dropping unwanted variables of a data frame in R. Say we have a data frame ‘grade’ in the current R working session, and we try to remove variables ‘Math’ and ‘Physics’. The first method is just using minus – symbol in front of the column number Read more