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…

How to sort datasets in R

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! Data frame is the most widely used object type in R data analysis, because it allows storing different modes of data in a tabular form. The rows of a data frame represents each observation, and the columns denotes different variables each observation has. When the data is collected and read into a data frame, Read more…

How to rename variables in R

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! When we have created a data frame in R , for example by reading a csv file from working directory, the first row of the file will be used as the column or variable names of the data frame. Then we can use names() function to rename the variable names as we like. In Read more…

How to read excel spreadsheet into a data frame in R

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! Data frames in R are the mostly widely used object type in R data analysis, due to the fact that a data frame can afford to have different variables with different modes(numeric, character, Boolean, etc). The data sources that are adaptable to create a data frame in R are versatile. Excel files are such Read more…

How to create numerical lists in Python

We provide effective and economically affordable training courses for R and Python, click here for more details and course registration ! Although a numerical list can be created manually by filling each element within square brackets in Python, very often will the analyst use some type of ready functions. For example in the following code example, we first try using a for loop with a range() function to print out number 1,2,3,4, then use list() Read more…