Nizamuddin Siddiqui has Published 2307 Articles

How to multiply a matrix with a vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 14:13:41

5K+ Views

When we multiply a matrix with a vector the output is a vector. Suppose we have a matrix M and vector V then they can be multiplied as M%*%V. To understand the step-by-step multiplication, we can multiply each value in the vector with the row values in matrix and find ... Read More

How to replicate whole data frame and add it in the original one in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 14:04:48

1K+ Views

The replicates of a data frame in R can be created with the help of sapply function, to set the number of times we want to repeat the data frame we can use rep.int, times argument. For example, if we have a data frame df and we want to create ... Read More

How to find the day of the year from dates in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 14:02:00

6K+ Views

To find the day of the year from dates, we can use yday function of lubridate package. For example, if we have a date or a date of vectors then we simply need to pass that date or the vector inside yday function by using the below syntax −yday(“date”)oryday(“vector_of_date”)Loading lubridate ... Read More

How to calculate row means by excluding NA values in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 13:59:11

2K+ Views

To find the row means we can use rowMeans function but if we have some missing values in the data frame then na.rm=TRUE argument can be used in the same way as it is used while calculating the means for columns. For example, if we have a data frame df ... Read More

How to change the Y axis limit for boxplot created by using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 13:57:17

2K+ Views

One of the most important aspects of a boxplot is Y-axis labels because these labels help us to understand the limit of the variable. Since R generate these labels automatically in a good way, we stick with that but we can change that using coord_cartesian function with ylim as shown ... Read More

How to replace missing values with median in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 13:55:12

1K+ Views

To replace missing values with median, we can use the same trick that is used to replace missing values with mean. For example, if we have a data frame df that contain columns x and y where both of the columns contains some missing values then the missing values can ... Read More

How to extract a particular value based on index from an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 13:52:35

2K+ Views

Sometimes we want to figure out which value lies at some position in an R data frame column, this helps us to understand the data collection or data simulation process. For example, if we have a data frame df that contain columns x, y, and z each with 5000 values ... Read More

How to create a point chart for cumulative sums using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 13:47:12

943 Views

To create a point chart for cumulative sums using ggplot2, we need to use cumsum function for the dependent variable inside the aes function for aesthetic mapping that describes how the variable will be plotted. For example, if we have a data frame df that contain columns x and y ... Read More

How to combine two lists of same size to make a data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 13:32:11

810 Views

If we have two lists of same size then we can create a data frame using those lists and this can be easily done with the help of expand.grid function. The expand.grid function create a data frame from all combinations of the provided lists or vectors or factors. For example, ... Read More

How to multiply two vectors in R as in mathematics?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 13:29:28

5K+ Views

In mathematics, when two vectors are multiplied the output is a scalar quantity which is the sum of the product of the values. For example, if we have two vectors x and y each containing 1 and 2 then the multiplication of the two vectors will be 5. In R, ... Read More

Advertisements