Nizamuddin Siddiqui has Published 2307 Articles

How to display zero frequency for bars in base R barplot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 07:03:59

693 Views

When we create a barplot in base R, the bars are plotted for all the values in the vector but if we have a gap in the values then the bar with zero frequency for that gap is not plotted. For example, if we have a vector called x that ... Read More

How to apply one sample t-test on all columns of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 07:03:42

983 Views

When we want to apply t-test on columns of a data frame then we generally perform them one by one by accessing the appropriate columns but if we want to apply the test on all columns of the data frame then we can take the help of sapply function. For ... Read More

How to plot rows of a data frame as lines in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 07:03:19

4K+ Views

To plot row of a data frame as lines, we can use matplot function but we would need to transpose the data frame because transposed values of the data frame will be read as columns and the matplot function plot the columns not rows. For example, if we have a ... Read More

How to find the inverse of log10 for an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:55:42

1K+ Views

To find the log10 of a data frame column then log10 function will be used but to find the inverse of the log10 can be found by putting 10 raises to the power of the log10 column. For example, if we have a data frame called df that contains a ... Read More

How to split a vector by equal and different number of elements in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:40:40

852 Views

To split a vector by equal and different number of elements, we can use split function along with rep function. The rep function will define the repetition of the divisions for equal as well as different number of elements. For example, if a vector say x contains fifty values then ... Read More

How to extract the row for groupwise maximum in another column of an R data.table object?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

334 Views

To extract the row for groupwise maximum in another column of an R data.table object, can make use of which.max function by defining the grouping column. It means that if we have a categorical/grouping column and a numerical column then we groupwise maximum will be the maximum for each grouping ... Read More

How to find the number of non-empty values in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:38:24

2K+ Views

To find the number of non-empty values, we can find the negation of the sum of empty values which is actually the total number of non-empty values. For example, if we have a data frame df that contains a column x which has some empty values then to find the ... Read More

How to sort a vector in R based on manual position of elements?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:37:40

467 Views

To sort a vector based on manual position of elements, we can use order function along with the factor function. The factor function will help us to arrange the vector elements in the order we want by defining the levels as vector elements and order function will order them. Check ... Read More

How to create boxplot of vectors having different lengths in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

2K+ Views

If we have multiple vectors of different lengths then the boxplot for such vectors can be created by creating a single data frame using those vectors with a categorical column showing the name of the vectors and a numerical column having the corresponding values. Then boxplot function will be used ... Read More

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

380 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

Advertisements