Nizamuddin Siddiqui has Published 1958 Articles

How to change row values based on column values in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:31:00

544 Views

Changing row values based on column values means that we want to change the row values for a particular column if the column values satisfy a certain condition. For example, if we have a data frame called df that contains a column say x and we want to set all ... Read More

How to display raise to the power on X-axis in base R plot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:25:13

445 Views

To display anything different than the vector or column names on the axes, we need to use xlab for X-axis and ylab for Y-axis. Therefore, if we want to display raise to the power on X-axis then xlab argument will be along with the plot function. For example, if we ... Read More

How to create bar plot with log values using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:23:39

1K+ Views

To create the bar plot using ggplot2, we simply need to use geom_bar function and if we want to have the log scale of y variable then it can be set with aes under geom_bar. For example, if we have a data frame called df that contains a categorical column ... Read More

How to find the significant correlation in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:23:21

635 Views

To find the significant correlation in an R data frame, we would need to find the matrix of p-values for the correlation test. This can be done by using the function rcorr of Hmisc package and read the output as matrix. For example, if we have a data frame called ... Read More

How to get the colour name from colour code in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:22:31

629 Views

To get the color name from color code, we can use the color_id function of plotrix package. If we have a vector of colour codes say x then the colour name can be found by using the command sapply(x, color.id).ExampleLive Demo> x xOutput[1] "#FF0000" "#FF1F00" "#FF3D00" "#FF5C00" "#FF7A00" "#FF9900" "#FFB800" ... Read More

How to find the row sum for each column by row name in an R matrix?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:19:52

2K+ Views

To find the row sum for each column by row name, we can use rowsum function. For example, if we have a matrix called M then the row sums for each column with row names can be calculated by using the command rowsum(M, row.names(M)).Example1Live Demo> M1 rownames(M1) colnames(M1) M1Output    ... Read More

How to change the legend title in ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:19:33

514 Views

In ggplot2, by default the legend title is the title of the grouping column of the data frame. If we want to change that title then scale_color_discrete function. For example, if we have a data frame called df that contains two numerical columns x and y and one grouping column ... Read More

How to create group names for consecutively duplicate values in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:12:19

488 Views

The grouping of values can be done in many ways and one such way is if we have duplicate values or unique values then the group can be set based on that. If all the values are unique then there is no sense for grouping but if we have varying ... Read More

How to find the row-wise mode of a matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:11:00

702 Views

There is no in-built function to find the mode in R, hence we need to create one and then apply it to the rows of the matrix. The function for mode is created as follows −mode M1 M1Output     [, 1] [, 2] [, 3] [, 4] [, 5] [1, ... Read More

How to find the frequency table for factor columns in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 05:57:39

823 Views

If we have factor columns in an R data frame then we want to find the frequency of each factor level for all the factor columns. This can be done with the help of sapply function with table function. For example, if we have a data frame called df that ... Read More

Advertisements