Nizamuddin Siddiqui has Published 1958 Articles

How to check if a data frame column contains duplicate values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 07:25:26

2K+ Views

To check if a data frame column contains duplicate values, we can use duplicated function along with any. For example, if we have a data frame called df that contains a column ID then we can check whether ID contains duplicate values or not by using the command −any(duplicated(df$ID))Example1Consider the ... Read More

How to change the code "Yes" to 1 in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 14:07:30

16K+ Views

To change the code “Yes” to 1, we can use ifelse function and set the Yes to 1 and others to 0. For example, if we have a data frame called df that contains a character column x which has Yes and No values then we can convert those values ... Read More

How to find the count of a particular character in a string vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 14:02:00

206 Views

To find the count of a particular character in a string vector we can use nchar function along with gsub. For example, if we have a vector called x that contains string such India, Russia, Indonesia then we can find the number of times character i occurred then we can ... Read More

How to find the mean squared error for linear model in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 14:01:33

4K+ Views

To find the mean squared error for linear model, we can use predicted values of the model and find the error from dependent variable then take its square and the mean of the whole output. For example, if we have a linear model called M for a data frame df ... Read More

How to create a data frame column with letters of both size in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:57:25

432 Views

To create a data frame column with letters of both sizes, we can simply use the letters function and LETTERS function, the first one corresponds to lowercase letters and the latter corresponds to uppercase letters with single square brackets as shown in the below examples.Example1 Live Demodf1

How to find the index of the nearest smallest number in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:55:20

234 Views

To find the index of the nearest smallest number in an R data frame column, we can use which function along with subsetting for the value for which we want to find the index of the nearest smallest number. To understand how it can be done check out the below ... Read More

How to create a date vector with randomization in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:49:43

274 Views

To create a date vector with randomization, we can use sample function but the dates need to be read with as.Date function. For example, if we have 2 dates say 2021-01-01 and 2021-02-02 then a vector with randomization of these three dates can be created by using the command −sample(c(as.Date("2021-01-01"), ... Read More

How to multiply large numbers with all digits in the output in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:48:11

306 Views

To multiply large numbers with all digits in the output, we can use mul.bigz function of gmp package. For example, if we have two vectors say x and y each containing numbers of large size then the multiplication of these numbers that will return all the digits of the multiplication ... Read More

How to show values in boxplot in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:46:44

5K+ Views

The main values in a boxplot are minimum, first quartile, median, third quartile, and the maximum, and this group of values is also called five-number summary. Therefore, if we want to show values in boxplot then we can use text function and provide the five-number summary and labels with fivenum ... Read More

How to create a horizontal boxplot in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:46:26

3K+ Views

To create a horizontal boxplot in base R, we can set the horizontal argument inside boxplot function to TRUE. For example, if we have a vector called x then the horizontal histogram of that vector can be created by using the command boxplot(x,horizontal=TRUE).Example1x

Advertisements