Nizamuddin Siddiqui has Published 2307 Articles

How to convert list elements into a single string in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 07:13:37

3K+ Views

To convert list elements into a single string, we can use paste function but firstly we would need to unlist the elements. Also, since we want to create a single string double quotes will be required at the end of the output. For example, if we have a list that ... Read More

How to deal with the error “Error in int_abline---plot.new has not been called yet” in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 07:12:38

4K+ Views

The above error means plot is not being created yet hence abline function cannot be used to draw anything on the plot. Therefore, a plot needs to be created first to use abline function for creating a line or any other thing. Mostly, abline is used to create regression line ... Read More

How to replace a complete column in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 07:09:42

301 Views

To replace a complete column in an R data frame, we can set the original one to new values by using delta operator. For example, if we have a data frame called df that contains a column x which 500 has values from normal distribution then to replace it with ... Read More

How to change the partial plot background using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 07:08:00

652 Views

To change the partial plot background, we can create a rectangle using geom_rect function by defining both the axes values and alpha for transparency, the color will be changed by using fill argument. The value of alpha will completely hide the grey background and we can play with its value ... Read More

How to convert NaN to NA in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

9K+ Views

To convert NaN to NA in an R data frame, we can set the NaN values to NA values by using single square brackets. Firstly, we would need to access the column that contains NaN values then NaN values will be accessed using is.nan then we can set those values ... Read More

How to create a dummy variable in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:48:02

942 Views

A dummy variable is a type of variable that takes a value of 1 if the value for which the dummy variable is created exists in the data frame, otherwise it takes 0. Therefore, if we have a one binary variable in a data frame then there will be two ... Read More

How to convert binary variable to 0/1 format in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:42:56

7K+ Views

A binary variable is a type of variable that can take only two possible values like gender that has two categories male and female, citizenship of a country with two categories as yes and no, etc. If the binary variable is not in 0/1 format then it can be converted ... Read More

How to add an extra point to scatterplot using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:40:20

12K+ Views

To add an extra point to scatterplot using ggplot2, we can still use geom_point function. We just need to use aes function for quoting with new values for the variables, also we can change the color of this point using colour argument. The display of an extra point will help ... Read More

How to extract words from a string vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:38:56

3K+ Views

To extract words from a string vector, we can use word function of stringr package. For example, if we have a vector called x that contains 100 words then first 20 words can be extracted by using the command word(x, start=1, end=20, sep=fixed(" ")). If we want to start at ... Read More

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

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Feb-2021 06:36:15

93 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 ... Read More

Advertisements