Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 71 of 196

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Mar-2021 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 below data frame − Live DemoID

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 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 to 1 and 0 using the command ifelse(df$x=="Yes",1,0).Example1Consider the below data frame − Live DemoAgree

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 207 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 use the command nchar(gsub("[^i]","",x)) and the output will be 1 1 1 because first I’s in India and Indonesia will not be considered as they are in uppercase.Example1 Live Demox1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 06-Mar-2021 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 then we can find the mean squared error using the command mean((df$y-predict(M))^2).Example1Consider the below data frame − Live Demox1

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 434 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

Read More

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 236 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 examples.Example1Consider the below data frame − Live DemoID

Read More

How to create a date vector with randomization in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 06-Mar-2021 277 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"),as.Date("2021-02-02")),100,replace=TRUE)Example1 Live DemoDate1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 06-Mar-2021 307 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 can be done by using the command mul.bigz(x,y).Example1Loading gmp package and multiplying vectors containing large number values −library(gmp) x1

Read More

How to show values in boxplot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 06-Mar-2021 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 function as shown in the below examples.Example1x

Read More

How to create a horizontal boxplot in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 06-Mar-2021 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

Read More
Showing 701–710 of 1,958 articles
« Prev 1 69 70 71 72 73 196 Next »
Advertisements