Nizamuddin Siddiqui has Published 2307 Articles

How to remove spaces at the end in string vectors in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:27:44

357 Views

Sometimes values in a string vector has an extra space at the end, this might happen while typing the values or due to some other manual errors. To remove spaces at the end in string vectors, we can use gsub function. For example, if we have a vector called x ... Read More

How to create an integer64 vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:25:44

733 Views

The integer64 vector contains vector values that represents signed integers with values that range from negative 9, 223, 372, 036, 854, 775, 808 to positive 9, 223, 372, 036, 854, 775, 807. To create an integer64 vector, we can use as.integer64 function of bit64 package. The difference between integer64 vector ... Read More

How to use pnorm function on data frame columns in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:23:19

557 Views

The pnorm function is used to find the probability for a normally distributed random variable. Probabilities such as less than mean, greater than mean, or probability between left- and right-hand side of the mean. If we want to use pnorm function on data frame columns then apply function can help ... Read More

How to define the breaks for a histogram using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:17:18

6K+ Views

To manually define the breaks for a histogram using ggplot2, we can use breaks argument in the geom_histogram function. While creating the number of breaks we must be careful about the starting point and the difference between values for breaks. This will define the number of bars for histogram so ... Read More

How to fill NA values with previous values in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:10:49

1K+ Views

To fill NA values with next and previous values, we can use na.locf function of zoo package with fromLast = TRUE. This is the situation of a column as shown below −x 0 NA NA 1 1 NA 0 1The output after filling NA values with next and previous values ... Read More

How to hide NA values in an R matrix?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:04:18

180 Views

The hiding of NA values does not mean removal of NA values. If we have some NA values in an R matrix then we can hide them using blanks with double quotes. For example, suppose we have a matrix called M that contains some NA values then M can be ... Read More

How to save a csv and read using fread in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

543 Views

To save a csv file, we can use write.csv function in R and if we want to read it using fread then fread function will be used with the name of the csv file. The benefit of reading the csv file with fread function is that there will be a ... Read More

How to fix the lower value for X-axis in base R

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 05:51:47

261 Views

To fix the lower value for X-axis in base R, we can use xlim argument in plot function. Mostly, we set the lower value to zero but it is not necessary it can be something else, either less than zero or greater than zero as well. If only lower value ... Read More

How to create a boxplot with log of the variable in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

2K+ Views

To create a boxplot with log of the variable in base R, we need to use log argument within the boxplot function but we need to carefully pass the Y-axis inside the function because the values of the boxplot are plotted on the Y-axis. For example, if we have a ... Read More

How to plot matrix columns as lines in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

1K+ Views

To plot matrix columns as lines in base R, we can use matplot function but we need to read the matrix as a data frame using as.data.frame function and for creating lines the type argument will be used. For example, if we have a matrix called M then the columns ... Read More

Advertisements