Nizamuddin Siddiqui has Published 2307 Articles

How to remove names from a named vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Jan-2021 06:10:12

6K+ Views

To assign names to the values of vector, we can use names function and the removal of names can be done by using unname function. For example, if we have a vector x that has elements with names and we want to remove the names of those elements then we ... Read More

How to convert a string vector into title case in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Jan-2021 06:08:33

497 Views

We cannot be sure about the data characteristics we get for analysis and mostly it is not well organised, thus, the first task would be to make it more organised. The string values not in title case should also be taken care of if it is especially supposed to be ... Read More

How to set a specific value for a range in an R vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Jan-2021 06:05:46

284 Views

Suppose we have a vector that contains hundred values starting from 1 to 100 and we want to set values greater than 5 and less than 96 to 5 then it can be done with the help of ifelse function. For example, if such vector is named as x then ... Read More

How to find the number of positive values in an R vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Jan-2021 06:04:20

1K+ Views

We know that positive values are greater than 0, therefore, we can use this condition with length function to find the number of positive values in a vector. For example, if we have a vector x that contains some positive and some negative values and we want to find the ... Read More

How to check if all values in a vector are integer or not in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Jan-2021 06:03:06

2K+ Views

To check whether all values in a vector in R are integer or not, we can round the vector using floor function then subtract the vector values from it and check whether the output is zero or not. If the output will be zero that means the value is integer ... Read More

How to convert a matrix into a data frame with column names and row names as variables in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Jan-2021 06:01:36

1K+ Views

To convert a matrix into a data frame with column names and row names as variables, we first need to convert the matrix into a table and then read it as data frame using as.data.frame. For example, if we have a matrix M then it can be done by using ... Read More

How to create an empty data frame with fixed number of rows and without columns in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Jan-2021 06:00:17

1K+ Views

To create an empty data frame with fixed number of rows but no columns, we can use data.frame function along with the matrix function. That means we need to create a matrix without any column using matrix and save it in a data frame using data.frame function as shown in ... Read More

How to create a residual plot in R with better looking aesthetics?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Jan-2021 06:57:21

255 Views

The default residual plot can be created by using the model object name in base R but that is not very attractive. To create a residual plot with better looking aesthetics, we can use resid_panel function of ggResidpanel package. It is created in the same way as the residual plot ... Read More

How to create combinations for each string values in two vectors in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Jan-2021 06:56:05

457 Views

If we have two string vectors, each containing more than two values then it becomes a little difficult to create the combinations for each string value in those two vectors. For this purpose, we can make use of do.call function paste0 and expand.grid as shown in the below examples.ExampleLive Demo> ... Read More

How to get top values of a numerical column of an R data frame in decreasing order?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Jan-2021 06:54:16

6K+ Views

To get the top values in an R data frame, we can use the head function and if we want the values in decreasing order then sort function will be required. Therefore, we need to use the combination of head and sort function to find the top values in decreasing ... Read More

Advertisements