Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 86 of 196

How to find the rate of return for a vector values in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Feb-2021 200 Views

To find the rate of return for a vector values, we can use the formula for rate of return. For example, if we have a vector called x then the rate of return can be calculated by using the syntax diff(x)/x[-length(x)]. The output will be in decimal form and if we want to convert it to percentage then the output needs to be multiplied with 100, we can also input the same within the formula as (diff(x)/x[-length(x)])*100.Example Live Demox1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Feb-2021 511 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 that contains string values with spaces at the end then the removal of values can be done by using the command gsub(" $","",x,perl=T)Example Live Demox1

Read More

How to create an integer64 vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Feb-2021 1K+ 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 and others is that a large number of values can be stored in the vector.Examplelibrary(bit64) x1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Feb-2021 755 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 us.Consider the below data frame −Example Live Demox1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Feb-2021 8K+ 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 it should be taken seriously and should be according to the distribution of the data.Consider the below data frame −Example Live Demox

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 2K+ 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 will be −x 0 0 0 1 1 1 0 1Consider the below data frame −Example Live Demox1

Read More

How to hide NA values in an R matrix?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Feb-2021 329 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 printed by hiding NA value using print.table(M,na.print="")Example Live DemoM1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Feb-2021 828 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 variable added to the original csv file which contains the id as integers starting from 1 to the length of column values.Consider the below data frame −Example Live Demox

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Feb-2021 426 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 needs to be fixed then upper value will be set by using the max function as shown in the below example.Examplex

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Feb-2021 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 vector called x then the boxplot of log of x will be created as boxplot(x,log="y").Examplex

Read More
Showing 851–860 of 1,958 articles
« Prev 1 84 85 86 87 88 196 Next »
Advertisements