Nizamuddin Siddiqui has Published 2307 Articles

How to replace missing values with row means in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Feb-2021 10:49:08

632 Views

If we have similar characteristics in each column of an R data frame then we can replace the missing values with row means. To replace the missing values with row means we can use the na.aggregate function of zoo package but we would need to use the transposed version of ... Read More

How to find the sum by distinct column for factor levels in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Feb-2021 10:44:52

519 Views

If the data frame contains a factor column and some numerical columns then we might want to find the sum of numerical columns for the factor levels. For this purpose, we can use aggregate function. For example, if we have a data frame df that contains a factor column defined ... Read More

How to create a dotchart using ggplot2 without gridlines in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Feb-2021 10:39:53

196 Views

To create a dotchart using ggplot2 in R, we can use geom_dotplot function but the default gridlines will be in the output. If we want to remove the gridlines from the plot then theme function can be added in the rest of the command as theme(panel.grid=element_blank()).Example Live DemoConsider the below data ... Read More

How to change the repeated row names and column names to a sequence in a matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Feb-2021 10:37:08

335 Views

To change the repeated row names and column names to a sequence, we first need to read those names in a vector then set them to row names and column names with make.unique function. For example, if a matrix has row names defined as A, B, A, B, A then ... Read More

How to create a line chart with mean and standard deviation using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Feb-2021 10:28:10

2K+ Views

Sometimes we have mean and standard deviation given for groups or factors, these are generally obtained from previous research studies and is referred to as the secondary data. In this case. the line chart with mean and standard deviation using ggplot2 can be created by defining the minimum and maximum ... Read More

How to find the mean of multiple columns based on a character column in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Feb-2021 10:24:29

246 Views

If we have a character column that means we are more likely to have duplicated values in that column hence finding the mean of numerical columns based on the values in character column cannot be done directly. For this purpose, we can use aggregate function as shown in the below ... Read More

How to convert matrix rows into a list in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Feb-2021 10:17:13

1K+ Views

Depending on our objective, a matrix rows might be needed to converted into a list that means each row will be an element of the list. This can be done by using the function as.list but firstly we need to convert the matrix into data frame after transposing. For example, ... Read More

How to create bins for a continuous vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Feb-2021 10:11:01

3K+ Views

To create the bins for a continuous vector, we can use cut function and store the bins in a data frame along with the original vector. The values in the cut function must be passed based on the range of the vector values, otherwise, there will be NA’s in the ... Read More

How to convert a character data frame to numeric data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Feb-2021 10:08:30

2K+ Views

Sometimes numerical values are recorded as character values and we need to convert them to numeric type before starting our analysis. This is also possible for a whole data frame in R. Therefore, we can use sapply function to convert the columns of the data frame to numeric type and ... Read More

How to create a boxplot without frame in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Feb-2021 10:05:39

603 Views

The boxplot in base R is covered with a box and that box is called a frame. We can get rid of that frame by using frame argument while creating the boxplot. For example, if we have a vector called x and we want to create the boxplot without frame ... Read More

Advertisements