Nizamuddin Siddiqui has Published 2307 Articles

How to find the correlation coefficient between rows of two data frames in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 18-Oct-2020 14:18:17

690 Views

It is common the find the correlation coefficient between columns of an R data frame but we might want to find the correlation coefficient between rows of two data frames. This might be needed in situations where we expect that there exists some relationship row of an R data frame ... Read More

How to deal with warning message `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. in R while creating a histogram?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 18-Oct-2020 14:16:46

7K+ Views

The default value for bins is 30 but if we don’t pass that in geom_histogram then the warning message is shown by R in most of the cases. To avoid that, we can simply put bins=30 inside the geom_histogram() function. This will stop showing the warning message.Consider the below data ... Read More

How to save an R data frame as txt file?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 18-Oct-2020 14:16:06

2K+ Views

If we want to use a data frame created in R in the future then it is better to save that data frame as txt file because it is obvious that data creation takes time. This can be done by using write.table function. For example, if we have a data ... Read More

How to create a string vector with numbers at the end in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 18-Oct-2020 14:15:08

563 Views

If we want to create a categorical vector with all unique values representing strings with numbers at the end then paste0 function can help us in the same. For example, if we want to create a vector for ID up to 10 as ID1, ID2, ID3, ID4, ID5, ID6, ID7, ... Read More

How to replace NA values in columns of an R data frame form the mean of that column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 18-Oct-2020 14:05:48

7K+ Views

In the whole world, the first step people teach to impute missing values is replacing them with the relevant mean. That means if we have a column which has some missing values then replace it with the mean of the remaining values. In R, we can do this by replacing ... Read More

How to combine year, month, and day column in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 18-Oct-2020 14:04:22

6K+ Views

Sometimes date variable is recorded in three different columns representing year, month, and day instead of a single column as date. Therefore, we need to combine these three columns and create a single column. This can be done by using paste function and define the values with as.Date.Consider the below ... Read More

How to create a subset of a matrix in R using row names?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 18-Oct-2020 14:02:04

469 Views

When we create a matrix in R, the row names and column names are not defined but we can define them separately. If we want to take a subset of rows of a matrix then row numbers can be used within single square brackets but if we want to do ... Read More

How to replicate a vector to create matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 14:44:04

2K+ Views

The matrix can be created by using matrix function in R and if we want to create a matrix by replicating a vector then we just need to focus on the replication. For example, if we have a vector V and we want to create matrix by replicating V two ... Read More

How to create a random sample with values 0 and 1 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 14:30:01

1K+ Views

It is known that the random sample can be created by using sample function in R. If we want to create a random sample with values 0 and 1 only then there are three different ways to pass them inside the sample function −Creating a vector of 0 and 1Using ... Read More

How to align the bars of a barplot with the X-axis using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 14:16:21

1K+ Views

The bar plot is created with geom_bar function but there always exist some space between the bars and the X-axis labels. If we want to reduce that space or completely remove it we need to use scale_y_continuous function by defining expand argument for former and scale_y_continuous(expand=c(0, 0)) for latter.Example Live DemoConsider ... Read More

Advertisements